CGPath CGContext UIBezierPath的比較

來源:互聯網
上載者:User
////  PathView.m//  Qauze////  Created by apple on 16/6/2.//  Copyright © 2016年 李重陽. All rights reserved.//#import "PathView.h"@implementation PathView- (instancetype)initWithFrame:(CGRect)frame {    if (self = [super initWithFrame:frame]) {        self.backgroundColor = [UIColor blueColor];    }    return self;}- (void)drawRect:(CGRect)rect {    [self CGPath];    [self CGContext];    [self bezier];    [self drawRound];}/* *  一: CGPath **/- (void)CGPath {    CGContextRef ref = UIGraphicsGetCurrentContext();    CGMutablePathRef pathRef = CGPathCreateMutable();    //1.設定起點    CGPathMoveToPoint(pathRef, nil, 5, 5);    //2.加入線    CGPathAddLineToPoint(pathRef, nil, 50, 50);    //3.把path 放到contextRef 中    CGContextAddPath(ref, pathRef);    CGPathRelease(pathRef);    [[UIColor redColor]setStroke];//    CGContextSetStrokeColorWithColor(ref, [UIColor redColor].CGColor);    /*      *這句話必須加上去 否則 不會開始繪製     *這句話是開始繪製CGPath路徑     **/    CGContextStrokePath(ref);}/* * 二: 直接用CGContext 繪製 **/- (void)CGContext {    CGContextRef ref = UIGraphicsGetCurrentContext();    CGContextMoveToPoint(ref, 50, 50);    CGContextAddLineToPoint(ref, 100, 100);    CGContextAddLineToPoint(ref, 10, 60);    CGContextSetLineWidth(ref, 5);    CGContextSetLineCap(ref, kCGLineCapRound);    CGContextSetLineJoin(ref, kCGLineJoinBevel);    [[UIColor yellowColor]setFill];    [[UIColor cyanColor]setStroke];    /*     * 3種方法繪製 path     * 1.CGContextFillPath(ref); 繪製填充     * 2.CGContextStrokePath(ref); 繪製 筆觸     * 3.CGContextDrawPath(ref, kCGPathFillStroke); 繪製填充和筆觸     **/    CGContextDrawPath(ref, kCGPathFillStroke);}/* * 貝茲路徑 **/- (void)bezier {    UIBezierPath * path = [UIBezierPath bezierPath];    [path moveToPoint:CGPointMake(100,100)];    [path addLineToPoint:CGPointMake(200, 100)];    [path addLineToPoint:CGPointMake(150, 200)];    [path setLineCapStyle:kCGLineCapRound];    [path setLineJoinStyle:kCGLineJoinBevel];    [path setLineWidth:5];    [[UIColor redColor]setFill];    [[UIColor yellowColor]setStroke];    [path stroke];    [path fill];    [path closePath];}/* * 貝茲路徑繪製 圓 ,橢圓 ,扇形 **/- (void)drawRound {    //繪製圓    UIBezierPath * path = [UIBezierPath bezierPath];    [path addArcWithCenter:CGPointMake(100, 100) radius:50 startAngle:0 endAngle:M_PI*1.5 clockwise:YES];    [path setLineWidth:10];    [[UIColor yellowColor]setStroke];    [path stroke];    //繪製橢圓    UIBezierPath * path1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 200)];    [path1 setLineWidth:5];    [path1 stroke];}@end

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.