美文网首页
贝塞尔曲线(UIBezierPath)属性、方法汇总

贝塞尔曲线(UIBezierPath)属性、方法汇总

作者: 西瓜皮奥特曼 | 来源:发表于2017-03-15 11:24 被阅读20次

    原文链接:http://www.cnblogs.com/zhangying-domy/archive/2016/07/04/5640745.html

    Quartz 2D 绘图技术原文:http://www.jianshu.com/p/020a81d625ee

    //三角形

    -(void)drawRect:(CGRect)rect

    {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

    CGContextSetLineWidth(context, 2.f);

    CGContextSetLineJoin(context, kCGLineJoinRound);

    CGContextSetLineCap(context, kCGLineCapRound);

    CGPoint apoint[3];

    apoint[0] = CGPointMake(100, 120);

    apoint[1] = CGPointMake(150, 120);

    apoint[2] = CGPointMake(150, 160);

    CGContextAddLines(context, apoint, 3);

    CGContextClosePath(context);

    CGContextDrawPath(context, kCGPathFillStroke);

    }

    //矩形

    -(void)drawRect:(CGRect)rect

    {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

    CGContextSetLineWidth(context, 2.f);

    CGContextSetLineJoin(context, kCGLineJoinRound);

    CGContextSetLineCap(context, kCGLineCapRound);

    CGContextAddRect(context, CGRectMake(100, 120, 50, 50));

    CGContextDrawPath(context, kCGPathFillStroke);

    }

    //圆

    -(void)drawRect:(CGRect)rect

    {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

    CGContextSetLineWidth(context, 2.f);

    CGContextAddEllipseInRect(context, CGRectMake(100, 120, 200, 100));

    CGContextDrawPath(context, kCGPathFillStroke);

    }

    //圆弧

    -(void)drawRect:(CGRect)rect

    {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

    CGContextSetLineWidth(context, 2.f);

    CGContextSetLineCap(context, kCGLineCapRound);

    // 绘制圆弧方法1 (参数由左至右分别是,图形上下文、圆心x、圆心y、半径、起始弧度、结束弧度、圆弧伸展的方向(0为顺时针,1为逆时针))

    CGContextAddArc(context, 150, 100, 100, arc(0), arc(160), 0);

    CGContextClosePath(context);

    CGContextDrawPath(context, kCGPathFillStroke);

    }

    //�文字

    -(void)drawRect:(CGRect)rect

    {

    NSString * str = @"www.jianshu.com";

    NSMutableDictionary * attributes = [NSMutableDictionary dictionary];

    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:20];

    attributes[NSBackgroundColorAttributeName] = [UIColor whiteColor];

    attributes[NSForegroundColorAttributeName] = [UIColor redColor];

    [str drawInRect:CGRectMake(100, 100, 200, 30) withAttributes:attributes];

    }

    //�图片

    -(void)drawRect:(CGRect)rect

    {

    UIImage * image = [UIImage imageNamed:@"123456.jpg"];

    [image drawInRect:rect];

    }

    -(void)drawRect:(CGRect)rect

    {

    //直线

    [[UIColor redColor] setStroke];

    UIBezierPath * path = [UIBezierPath bezierPath];

    path.lineWidth = 2.0;

    path.lineCapStyle = kCGLineCapRound;

    path.lineJoinStyle = kCGLineJoinRound;

    [path moveToPoint:CGPointMake(10, 20)];

    [path addLineToPoint:CGPointMake(50, 20)];

    [path closePath];

    [path stroke];

    //三角形

    [[UIColor redColor] setStroke];

    UIBezierPath * path1 = [UIBezierPath bezierPath];

    path1.lineWidth = 2.0;

    path1.lineCapStyle = kCGLineCapRound;

    path1.lineJoinStyle = kCGLineJoinRound;

    [path1 moveToPoint:CGPointMake(10, 30)];

    [path1 addLineToPoint:CGPointMake(50, 30)];

    [path1 addLineToPoint:CGPointMake(30, 60)];

    [path1 closePath];

    [path1 stroke];

    //长方形

    [[UIColor redColor] setStroke];

    UIBezierPath * path2 = [UIBezierPath bezierPathWithRect:CGRectMake(10, 80, 100, 50)];

    [path2 stroke];

    //圆弧

    [[UIColor redColor] setStroke];

    UIBezierPath * path3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 100) radius:50 startAngle:arc(0) endAngle:arc(120) clockwise:YES];

    [path3 stroke];

    //圆

    [[UIColor redColor] setStroke];

    UIBezierPath * path4 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(200, 300, 100, 100) cornerRadius:50];

    [path4 stroke];

    [[UIColor redColor] setStroke];

    UIBezierPath * path5 = [UIBezierPath bezierPath];

    [path5 moveToPoint:CGPointMake(20, 200)];

    [path5 addCurveToPoint:CGPointMake(120, 200) controlPoint1:CGPointMake(45, 150) controlPoint2:CGPointMake(95, 250)];

    //    [path5 addQuadCurveToPoint:CGPointMake(120, 200) controlPoint:CGPointMake(45, 150)];

    [path5 stroke];

    }

    相关文章

      网友评论

          本文标题:贝塞尔曲线(UIBezierPath)属性、方法汇总

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