0

Trying to draw a shadow using code from this question: How do I draw a shadow under a UIView?

I implement it in a UIView subclass as discussed, but when I try and use it using UIView *shadow = [[ShadowView alloc]initWithFrame:CGRectMake(100,100,100,100)]; I get only a black square, rather than something resembling shadow.

Am I missing something here?

Community
  • 1
  • 1
dc.
  • 1,429
  • 2
  • 17
  • 29

2 Answers2

1

I know this an ancient question, but I came across it via google as I was trying to do the same thing. So I thought I would post incase anyone else has the same problem. I finally discovered a fix after reading this tutorial: http://www.raywenderlich.com/2134/core-graphics-101-glossy-buttons

You need to either uncheck Opaque, and set the Background to Clear Color in IB.

OR as shown in the tutorial set them in initWithCoder

-(id) initWithCoder:(NSCoder *)aDecoder {
    if ((self = [super initWithCoder:aDecoder])) {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Novaoblivion
  • 11
  • 1
  • 3
0

Yup, you probably need to explicitly add an #import to the top of your class. I've had the same issue before and that fixed it. (Can't exactly explain why though)

Brad The App Guy
  • 16,255
  • 2
  • 41
  • 60
  • That can't be it. If I didn't have the import the compiler would throw an error at me. Regardless, I have #import "ShadowView.h" in my header. – dc. May 28 '10 at 21:24