美文网首页
UIView - 绘制多边形

UIView - 绘制多边形

作者: 会飞的大西瓜v | 来源:发表于2017-04-01 10:10 被阅读63次
// 需要多边形的视图
    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];

相关文章

网友评论

      本文标题:UIView - 绘制多边形

      本文链接:https://www.haomeiwen.com/subject/bxqiottx.html