1

Am not sure where an wrong. I have an UIImageView in Storyboard, which am connecting with an IBOutlet to the code. I want to add a shadow (during runtime) to the UIImageView. And am using this code snippet for that (got this help from a stackoverflow post) :

-(void) awakeFromNib { 
    self.imageViewTopBar.layer.shadowColor = [UIColor blueColor].CGColor;
    self.imageViewTopBar.layer.shadowOffset = CGSizeMake(0, 5);
    self.imageViewTopBar.layer.shadowOpacity = 1.0;
    self.imageViewTopBar.layer.shadowRadius = 3.0;
        //self.imageViewTopBar.layer.masksToBounds = YES;
    //self.imageViewTopBar.clipsToBounds = NO;
    self.imageViewTopBar.layer.shouldRasterize = YES;
}

but it simply doesn't work. Any help please? I don't see any reason why it shouldn't work.

My environment : XCode 4.5.2, iOS 5, iPhone 4

Daniel
  • 22,821
  • 12
  • 108
  • 150
Jean
  • 2,527
  • 6
  • 33
  • 59

3 Answers3

1

You should use -viewDidLoad to do this, check out this post: Accessing View in awakeFromNib?

Community
  • 1
  • 1
Daniel
  • 22,821
  • 12
  • 108
  • 150
0

Try putting it into viewDidLoad. I assume you've included the quartzcore framework. I think it would throw compiler error if not...

HackyStack
  • 4,609
  • 3
  • 21
  • 28
0

Do you have checked, in the xib, clipToBounds to YES?

If YES you should uncheck the clipToBounds and reorganize your view hierarchy.

Normally when i have an imageView with a shadow i use this hierarchy

(aImageView)   ClipToBounds=YES
     |
     |
   (aView)     Shadow setted here
     |
     |
 (Superview)

aView has the same frame size of the aImageView

Luca Bartoletti
  • 2,423
  • 1
  • 24
  • 46