- (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);
}
网友评论