美文网首页
iOS开发 贝塞尔曲线

iOS开发 贝塞尔曲线

作者: 喜剧收尾_XWX | 来源:发表于2021-01-11 14:22 被阅读0次

参考文章 https://www.jianshu.com/p/6c9aa9c5dd68


一、画线

画线效果
-(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];
}

相关文章

网友评论

      本文标题:iOS开发 贝塞尔曲线

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