[英]how to make Irregular shape uiview and put uiimageview inside those shapes like instacollage iphone app
I am working on a photo collage iphone app and i have to make irregular shape photo frames inside each shape there will be a uiimageview with gestures, on tapping the shape i need to pick a photo for that shape, these frames are very similar to frames of instacollage iphone app. 我正在使用照片拼贴iPhone应用程序,我必须在每个形状内制作不规则形状的相框,然后会有带有手势的uiimageview,在点击形状时,我需要为该形状选择照片,这些框架与框架非常相似istacollage iphone应用程序。 link : https://itunes.apple.com/in/app/instacollage-pro-pic-frame/id530957474?mt=8 链接: https : //itunes.apple.com/in/app/instacollage-pro-pic-frame/id530957474?mt=8
provide me some kind of direction how to do this task. 为我提供了如何执行此任务的指导。
Thanks 谢谢
You can use Mask property of the layer to achieve this. 您可以使用图层的Mask属性来实现此目的。
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.imageView.bounds ;
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithOvalInRect:maskLayer.frame];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [roundedPath CGPath];
// Add mask
self.imageView.layer.mask = maskLayer;
Thanks Sahana. 谢谢萨哈纳。 The equivalent code in Swift is: Swift中的等效代码是:
let maskLayer = CAShapeLayer()
maskLayer.frame = self.imageView.bounds
let roundedPath = UIBezierPath(ovalInRect: maskLayer.frame)
maskLayer.fillColor = UIColor.whiteColor().CGColor
maskLayer.backgroundColor = UIColor.clearColor().CGColor
maskLayer.path = roundedPath.CGPath
self.imageView.layer.mask = maskLayer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.