Duck
Duck

Reputation: 35933

iphone - UIImageView class shadow

I have a UIImageView based class.

At the start of this class, I have this.

  if ([super initWithFrame:frame] == nil) {
        return nil;
    }


    self.layer.cornerRadius = 6.0;
    self.layer.masksToBounds = YES;
    self.layer.shadowOffset = CGSizeMake(3,3);
    self.layer.shadowOpacity = 0.7f;
    self.layer.shadowRadius = 5.0;

    // bla bla

Despite the shadow being declared there, all objects created with this class using initWithFrame, don't show any shadow.

am I missing something?

thanks

Upvotes: 0

Views: 2097

Answers (2)

W Dyson
W Dyson

Reputation: 4634

Just add a CALayer under the image with a shadow. The image with a masksToBounds of YES and the shadow layer NO.

Upvotes: 0

Duck
Duck

Reputation: 35933

I figured out based on the commend of vodkhang.

The problem is

self.layer.masksToBounds = YES;

I suppose the mask clips the shadow.

Upvotes: 1

Related Questions