为图片添加边框和阴影效果需要用到图层。
先看一下demo效果图(上图是原图,下面则是效果图):
源码:
UIImageView *imageView = [[UIImageViewalloc]initWithImage:image];
imageView.frame = CGRectMake(50, 250, image.size.width, image.size.height);
//添加边框
//获得图层
CALayer *layer = imageView.layer;
layer.borderWidth = 2; //边框宽度
layer.borderColor = [[UIColorwhiteColor] CGColor];
//添加阴影
layer.shadowColor = [[UIColorblackColor] CGColor];
layer.shadowOffset = CGSizeMake(4, 4); //阴影向右及向下偏移量
layer.shadowRadius = 3; //阴影宽度
layer.shadowOpacity = 1;//阴影透明度
[self.viewaddSubview:imageView];