UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.backgroundColor = [UIColor redColor];
[self.view addSubview:imageView];
// 線的路徑
UIBezierPath *polygonPath = [UIBezierPath bezierPath];
// 這些點(diǎn)的位置都是相對于所在視圖的
// 起點(diǎn)
[polygonPath moveToPoint:CGPointMake(25, 5)];
// 其他點(diǎn)
[polygonPath addLineToPoint:CGPointMake(15, 15)];
[polygonPath addLineToPoint:CGPointMake(25, 25)];
// [polygonPath closePath]; // 添加一個(gè)結(jié)尾點(diǎn)和起點(diǎn)相同
CAShapeLayer *polygonLayer = [CAShapeLayer layer];
polygonLayer.lineWidth = 3;
polygonLayer.strokeColor = [UIColor whiteColor].CGColor;
polygonLayer.path = polygonPath.CGPath;
polygonLayer.fillColor = nil; // 默認(rèn)為blackColor
[imageView.layer addSublayer:polygonLayer];
參考鏈接:https://www.cnblogs.com/jaesun/p/iOS-CAShapeLayerUIBezierPath-hua-xian.html