1. 程式人生 > 其它 >iOS開發 貝塞爾曲線

iOS開發 貝塞爾曲線

技術標籤:ios軟體開發程式碼規範程式設計程式語言

參考文章 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