- (void)drawRect:(CGRect)rect {
//1.获得图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2.拼接图形(路径)
CGContextMoveToPoint(ctx, 10, 10);//设置一个起点
CGContextAddLineToPoint(ctx, 100, 100);//添加一条线段
CGContextAddLineToPoint(ctx, 150, 40);
CGContextClosePath(ctx);//关闭路径(连接起点和最后一个点)
//3.渲染显示到view上
CGContextStrokePath(ctx);
}
- (void)drawRect:(CGRect)rect {
//1.获得图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2.画矩形框
CGContextMoveToPoint(ctx, 10, 10); //设置一个起点
CGContextAddLineToPoint(ctx, 100, 100); //添加一条线段
CGContextMoveToPoint(ctx, 200, 190); //设置一个起点
CGContextAddLineToPoint(ctx, 150, 40); //添加一条线段
//设置线段属性(宽度、颜色)
CGContextSetLineWidth(ctx, 10);
CGContextSetRGBStrokeColor(ctx, 1.0, 0, 0, 1.0);
CGContextSetLineCap(ctx, kCGLineCapRound);//线段头尾圆角
CGContextSetLineJoin(ctx, kCGLineJoinRound); //线段转折点样式
//3.渲染显示到view上
CGContextStrokePath(ctx);
// CGContextFillPath(ctx);
}