需求:
需要实现一个控件周边有阴影的效果,由于以前没弄过,所以记录一下
效果:
效果图实现:
为了实现四周的效果,必须要设置阴影的路径,不然实现不了四周的效果
UIImageView *image = [UIImageView new];
image.frame = CGRectMake(100, 100, 300, 300);
[self.view addSubview:image];
self.image = image;
image.center = self.view.center;
image.image = [UIImage imageNamed:@"2.jpg"];
// image.layer.cornerRadius = 15;
//偏移距离
image.layer.shadowOffset = CGSizeMake(5, 5);
//透明度
image.layer.shadowOpacity = 0.8;
//阴影颜色
image.layer.shadowColor = [UIColor lightGrayColor].CGColor;
//阴影半径
image.layer.shadowRadius = 30;
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(-20,-20, image.frame.size.width + 40, image.frame.size.height + 40) cornerRadius:1.0];
//阴影路径
image.layer.shadowPath = path.CGPath;
网友评论