Add Round Corner to UIImageView and Shadow Shadow Effect

I have the same problem as the link here: Unable to add corner radius and shadow

if I put maskToBounds = YES, I get round corners, but no shadow. If I put maskToBounds = NO, I get a shadow, but not round corners.

Then I followed the instructions at this link above, setting maskToBounds = NO, but instead set the radius of the corner and set the bezier path of the shadow with a rounded rectangle, keeping the radius of two identical. "But then I don’t turn around the corners and get the shadow! (T. f. square image without shadow) Could you help me? I don’t know what I did wrong. Thank you in advance.

self.userImageView.backgroundColor = [UIColor redColor]; 
self.userImageView.clipsToBounds = NO; 
self.userImageView.contentMode = UIViewContentModeCenter; 
self.userImageView.layer.masksToBounds = NO; 

self.userImageView.layer.borderWidth = 1; 
self.userImageView.layer.borderColor = [[UIColor grayColor] CGColor]; 

self.userImageView.layer.shadowOpacity = 1; 
self.userImageView.layer.shadowColor = [[UIColor blackColor] CGColor]; 
self.userImageView.layer.shadowRadius = 8.0f; 
self.userImageView.layer.shadowOffset = CGSizeMake(-3, 0);
self.userImageView.layer.shouldRasterize = YES; 

self.userImageView.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:[self.userImageView bounds] cornerRadius:10.0f] CGPath]; 

[self addSubview:self.userImageView]; 
+5
source share
1 answer

, , UIImageView .

- UIImageView.

CGFloat cornerRadius = 3.0

UIView *container = [[UIView alloc] initWithFrame:aRect];
container.layer.shadowOffset = CGSizeMake(0, 0);
container.layer.shadowOpacity = 0.8;
container.layer.shadowRadius = 5.0;
container.layer.shadowColor = [UIColor redColor].CGColor;
container.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:container.bounds cornerRadius:cornerRadius] CGPath];

self.userImageView.layer.cornerRadius = cornerRadius;
self.userImageView.layer.masksToBounds = YES;
self.userImageView.frame = container.bounds;
[container addSubview:self.userImageView];
[self addSubview:container];
+18

All Articles