// 需要多边形的视图
UIView * delegation = [[UIView alloc]init];
delegation.backgroundColor = HEXCOLOR(0x4d4d4d);
[self.contentView addSubview:delegation];
[delegation mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView);
make.top.equalTo(self.grouponTypeLabel.mas_bottom).offset(YSCCommonPadding * 3);
make.height.mas_equalTo(60);
}];
// 线的路径,坐标都是相对于所在视图
UIBezierPath *polygonPath = [UIBezierPath bezierPath];
// 起点
[polygonPath moveToPoint:CGPointMake(SCREEN_WIDTH / 2 - 10, 0)];
// 其他点
[polygonPath addLineToPoint:CGPointMake(SCREEN_WIDTH / 2, - 10)];
[polygonPath addLineToPoint:CGPointMake(SCREEN_WIDTH / 2 + 10, 0)];
// 添加一个结尾点和起点相同
[polygonPath closePath];
CAShapeLayer *polygonLayer = [CAShapeLayer layer];
polygonLayer.path = polygonPath.CGPath;
polygonLayer.fillColor = HEXCOLOR(0x4d4d4d).CGColor; // 默认为blackColor
[delegation.layer addSublayer:polygonLayer];
网友评论