iOS

气泡图片

给ImageView加Layer

Posted by Alpaca on November 3, 2016

准备一张这种气泡效果的背景图,然后将这个气泡图做成一个layer实例,并且通过contentCenter或者contentRect拉伸至我们需要展示的UIImageView大小

将做好的layer实例赋给UIImageView

将imageview赋上图片

CGRect frame = CGRectMake(20, 100, 300, 300);

UIImageView *image = [[UIImageView alloc] initWithFrame:frame];

CAShapeLayer *layer = [CAShapeLayer layer];

layer.frame = image.bounds;
layer.contents = (id)[UIImage imageNamed:@"chat.png"].CGImage;
layer.contentsCenter = CGRectMake(0.5, 0.5, 0.1, 0.1);
layer.contentsScale = [UIScreen mainScreen].scale;

image.layer.mask = layer;
image.layer.frame = image.frame;
image.image = [UIImage imageNamed:@"1.jpg"];
[self.view addSubview:image];

Like this ⤵️:



分享文章到微博:
对您有点帮助? 您的支持将鼓励我继续创作!