简单的Quartz2D划线

//

//  CJWView.m

//  Quartz2D

//

//  Created by CJW on 16/7/13.

//  Copyright © 2016 ch. All rights reserved.

//


#import "CJWView.h"


@implementation CJWView



// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    //取得和当前视图相关联的图形上下文

    //如果是在drawrect方法中调用UIFRaphicsGetCurrentContext方法获取出来的就是layer的上下文

    CGContextRef   ctx = UIGraphicsGetCurrentContext();

    //绘图,设置起点

    CGContextMoveToPoint(ctx, 20, 100);

    //设置 终点

    CGContextAddLineToPoint(ctx, 300, 150);

    

    //设置颜色

    CGContextSetRGBStrokeColor(ctx, 0, 1.0, 0, 1.0);

    //设置线条宽度

    CGContextSetLineWidth(ctx, 15);

    //设置香甜起点和终点的样式为圆角

    CGContextSetLineCap(ctx, kCGLineCapRound);

    //设置线条的转角样式为圆角

    CGContextSetLineJoin(ctx, kCGLineJoinRound);

    //渲染空心(不能渲染成实心)

    CGContextStrokePath(ctx);

    

    //设置第二条线

    //设置第二条线的起点

    CGContextMoveToPoint(ctx, 50, 200);

    //设置第二条线的终点

    CGContextAddLineToPoint(ctx, 300, 60);

    //设置颜色

    [[UIColor grayColor] set];

    //设置线条宽度

    CGContextSetLineWidth(ctx, 10);

    //设置线条的起点和终点样式

    CGContextSetLineCap(ctx, kCGLineCapButt);

    //渲染

    CGContextStrokePath(ctx);

}



@end


鲜果图::

简单的Quartz2D划线_第1张图片




你可能感兴趣的:(Quartz2D,Quartz2D)