美文网首页
UIBezierPath

UIBezierPath

作者: Gui晨曦遇晓 | 来源:发表于2018-01-07 15:54 被阅读0次

    UIBezierPath

    • 画线
    - (void)drawRect:(CGRect)rect {
        //1.创建贝塞尔路径的实例
        UIBezierPath *path = [UIBezierPath bezierPath];
        //2.勾勒图形
        [path moveToPoint:CGPointMake(40, 40)];
        [path addLineToPoint:CGPointMake(140, 40)];
        [path addLineToPoint:CGPointMake(140, 140)];
        [path addLineToPoint:CGPointMake(40, 140)];
    //    [path addLineToPoint:CGPointMake(40, 40)];
        [path closePath];
    
    
        [path moveToPoint:CGPointMake(40, 200)];
        [path addLineToPoint:CGPointMake(140, 200)];
        [path addLineToPoint:CGPointMake(140, 300)];
        [path addLineToPoint:CGPointMake(40, 300)];
        [path closePath];
    
        //设置描边线的宽度
        path.lineWidth = 10;
        //焦点的样式
    //    kCGLineJoinMiter, //尖的
    //    kCGLineJoinRound, //圆的
    //    kCGLineJoinBevel  //斜的  角被砍掉
        path.lineJoinStyle = kCGLineJoinBevel;
        //线两端的样式
    //    kCGLineCapButt,  //方的
    //    kCGLineCapRound, //圆的 多出一块
    //    kCGLineCapSquare //方的 多出一块
        path.lineCapStyle = kCGLineCapSquare;
    
        //设置 描边颜色
        [[UIColor redColor] setStroke];
        //设置 填充颜色
        [[UIColor greenColor] setFill];
        //描边
        [path stroke];
        //填充
        [path fill];
    
    }
    
    • 画圆
    - (void)drawRect:(CGRect)rect {
        UIBezierPath *path = [UIBezierPath bezierPath];
        //clockwise 为YES顺时针  为NO逆时针
        [path addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:M_PI_2 * 3 endAngle:0 clockwise:YES];
        [path addLineToPoint:CGPointMake(100, 100)];
        [path closePath];
    
        //移动画笔
    //    [path moveToPoint:CGPointMake(100, 180)];
    //    [path addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
    //    [path addLineToPoint:CGPointMake(100, 100)];
    //    [path closePath];
    
    
        path.lineWidth = 8;
        [[UIColor redColor] setStroke];
        [path stroke];
        [[UIColor greenColor] setFill];
        [path fill];
    }
    
    • 画曲线
        UIBezierPath *path = [UIBezierPath bezierPath];
        [path moveToPoint:CGPointMake(140, 40)];
        //添加两个控制点 和 终点
        [path addCurveToPoint:CGPointMake(40, 180) controlPoint1:CGPointMake(40, 40) controlPoint2:CGPointMake(140, 180)];
    
        [path addCurveToPoint:CGPointMake(140, 320) controlPoint1:CGPointMake(140, 180) controlPoint2:CGPointMake(40, 320)];
    
        [[UIColor redColor]setStroke];
        [path stroke];
    
    • 画矩形
        UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, 80)];
        rectPath.lineWidth = 5;
        [[UIColor greenColor] setStroke];
        [rectPath stroke];
    
    • 绘制圆角矩形
        UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(50, 150, 200, 80) cornerRadius:20];
        [roundedRect stroke];
    
    • 绘制椭圆
        UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 250, 200, 80)];
        [oval stroke];
    

    相关文章

      网友评论

          本文标题:UIBezierPath

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