美文网首页
画带三角形view

画带三角形view

作者: 路边的风景呢 | 来源:发表于2018-12-10 10:17 被阅读11次

- (void)drawRect:(CGRect)rect {

    // 设置背景色

    [[UIColor colorWithRed:18/255.0 green:60/255.0 blue:105/255.0 alpha:1.0] set];

    //拿到当前视图准备好的画板

    CGContextRef context = UIGraphicsGetCurrentContext();

    //利用path进行绘制三角形

    CGContextBeginPath(context);

    CGPoint point = _trianglePoint;

    // 设置起点

    CGContextMoveToPoint(context, point.x, point.y);

    // 画线

    CGContextAddLineToPoint(context, point.x-6, point.y+10);

    CGContextAddLineToPoint(context, point.x+6, point.y+10);

    CGContextClosePath(context);

    // 设置填充色

    [[UIColor colorWithRed:18/255.0 green:60/255.0 blue:105/255.0 alpha:1.0] setFill];

    // 设置边框颜色

    [[UIColor colorWithRed:18/255.0 green:60/255.0 blue:105/255.0 alpha:1.0] setStroke];

    // 绘制路径

    CGContextDrawPath(context, kCGPathFillStroke);

}

相关文章

网友评论

      本文标题:画带三角形view

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