答案 0 :(得分:2)
我刚刚完成了(对于Swift 3,但它也可能对你有帮助),你应该有你的图像的插座,例如名为yourImage然后在viewDidLoad上执行此操作:
let shapeLayer = CAShapeLayer()
shapeLayer.path = UIBezierPath(roundedRect: yourImage.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 30, height: 30)).cgPath
yourImage.layer.mask = shapeLayer
答案 1 :(得分:2)
自从我上次编写Objective-c代码以来,它实际上是MONTHS,因为我想再次托盘,这是使用Swift 3.0编写的Mago Nicolas Palacios的Objective-c版本。
UIImageView *sampleImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sample"]];
CGSize size = CGSizeMake(30, 30);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:sampleImage.bounds
byRoundingCorners:(UIRectCornerBottomRight | UIRectCornerTopLeft)
cornerRadii:size];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setPath:[bezierPath CGPath]];
sampleImage.layer.mask = shapeLayer;