为图片和视图添加边框和阴影

2019-04-15 15:07发布

添加边框: //设置layer CALayer *layer=[backView layer]; //是否设置边框以及是否可见 [layer setMasksToBounds:YES]; //设置边框圆角的弧度 [layer setCornerRadius:10.0]; //设置边框线的宽 // [layer setBorderWidth:1]; //设置边框线的颜 {MOD} [layer setBorderColor:[[UIColor blackColor] CGColor]];
添加边框和阴影(以ImageView为例): //给iamgeview添加阴影 和边框 UIImageView * imgvPhoto = [UIImageView alloc] init]; //添加边框 CALayer * layer = [_imgvPhoto layer]; layer.borderColor = [ [UIColor whiteColor] CGColor]; layer.borderWidth = 5.0f; //添加四个边阴影 _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor; _imgvPhoto.layer.shadowOffset = CGSizeMake(0, 0); _imgvPhoto.layer.shadowOpacity = 0.5; _imgvPhoto.layer.shadowRadius = 10.0; //添加两个边阴影 _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor; _imgvPhoto.layer.shadowOffset = CGSizeMake(4, 4); _imgvPhoto.layer.shadowOpacity = 0.5; _imgvPhoto.layer.shadowRadius = 2.0;