在drawRect:(CGRect)rect方法中编写
一.画线/直线图形
UIColor *pathColor = [UIColor performSelector:colorSelector withObject:nil];
CGFloat r, g, b, a;
[pathColor getRed:&r green:&g blue:&b alpha:&a];
// 取得画布
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapSquare); // 设置终点类型
CGContextSetRGBStrokeColor(context, r, g, b, a); // 设置画笔颜色
CGContextBeginPath(context); // 开始绘画
CGContextMoveToPoint(context, leftPoint.x, leftPoint.y); // 设置点位置
CGContextAddLineToPoint(context, upPoint.x, upPoint.y); // 连线
CGContextStrokePath(context); // 绘线
二.画带有填充色的图形
// 在CGContextBeginPath后编写填充颜色代码
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextDrawPath(context, kCGPathFillStroke);
网友评论