参考文章 https://www.jianshu.com/p/6c9aa9c5dd68
作为一个开发者,有一个学习的氛围跟一个交流圈子特别重要,这是一个我的iOS交流群:812157648,不管你是小白还是大牛欢迎入驻 ,分享BAT,阿里面试题、面试经验,讨论技术, 大家一起交流学习成长!
一、画线
-(void)drawRect:(CGRect)rect{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)]; //设置起点
[path addLineToPoint:CGPointMake(50, 100)];
[path addLineToPoint:CGPointMake(150, 50)];
[path addLineToPoint:CGPointMake(300, 300)];
path.lineCapStyle = kCGLineCapRound;//终点类型
path.lineJoinStyle = kCGLineJoinRound;//交叉点类型
path.lineWidth = 10.0;
// UIColor *fillColor = [UIColor orangeColor];
// [fillColor set];
// [path fill]; //颜色填充
UIColor *redColor = [UIColor redColor];
[redColor set];
[path stroke];//划线
}
二、矩形
-(void)drawRect:(CGRect)rect{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, 200)];
path.lineWidth =5;
UIColor *strokeColor = [UIColor orangeColor];
[strokeColor set];
[path stroke];
}
三、椭圆、圆
#pragma mark -绘制圆圈、椭圆
-(void)drawRect:(CGRect)rect{
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 50, 200, 100)];
path.lineWidth =3.0;
UIColor *strokeColor = [UIColor orangeColor];
[strokeColor set];
[path stroke];
}
四、圆角矩形
#pragma mark -圆角矩形
-(void)drawRect:(CGRect)rect{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 50, 150, 150) cornerRadius:6];
path.lineWidth =2;
UIColor *fillcolor = [UIColor orangeColor];
[fillcolor set];
[path stroke];
}
五、矩形的某个角为圆角
#pragma mark -矩形的某个角为圆角
-(void)drawRect:(CGRect)rect{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 80, 150, 150) byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(20, 20)];
path.lineWidth =2;
UIColor *color = [UIColor orangeColor];
[color set];
[path stroke];
}
原文作者:喜剧收尾_XWX
原文地址:https://www.jianshu.com/p/2fca9a997d3a