Reputation: 1429
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?
Upvotes: 0
Views: 899
Reputation: 11
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;
}
Upvotes: 1
Reputation: 16275
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)
Upvotes: 0