简体   繁体   English

如何制作不规则形状的uiview并将uiimageview放入instacollage iphone app之类的形状中

[英]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.

相关问题 如何从iPhone的uiimageview中的不规则形状中仅获取像素? - how to get only pixels from inside a irregular shape from uiimageview in iphone? 使用UIImageView制作类似iPhone的Photo Galerry的应用 - Using UIImageView to make a app like iPhone's Photo Galerry 如何在 UIView 中放置一个 UITableViewController 来进行触摸开始在 iPhone 中工作? - How to put an UITableViewController in UIView to make touchesBegan to work in iPhone? 如何在iPhone SDK中检查UIView和UIImageView是否被触摸? - how to check UIView and UIImageView is touched or not in iphone sdk? 如何以编程方式将UIView或UIImageView与“内部触摸”等事件相关联? - How can I programmatically link an UIView or UIImageView with an event like “touch up inside”? 如何创建类似于iPhone的Apple Clock应用程序的“警报”部分中的选项卡? - How to create Tabs like those those in Alarm section of apple Clock app in iPhone? 如何在我的iPhone应用程序中创建UIView“可滚动”? - How do I make a UIView “scrollable” in my iPhone app? 超视觉iPhone应用程序,如UIView或UITableView滚动 - Ultravisual iPhone app like UIView or UITableView scroll UIVIew里面的UIButton没有集中在iPhone应用程序中 - UIButton inside UIVIew not centered in iPhone app 避免在UIView内部拉伸UIImageView - Avoid Stretching UIImageView inside a UIView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM