drawRect画线和使用CGContext

Quartz 2D绘图引擎,核心对象就是上下文

 

画线的一个自定义UILable

-(void)drawRect:(CGRect)rect

{

    [super drawRect:rect];

    // 1.获得上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    

    // 2.设置画笔颜色

    [self.textColor setStroke];

    

    // 3.设置画笔的起点和终点

    CGFloat y = rect.size.width * 0.5;

    CGContextMoveToPoint(ctx, 0, y);

    CGContextAddLineToPoint(ctx, rect.size.width, y);

    

    // 4.画线

    CGContextStrokePath(ctx);    

}

原文地址:https://www.cnblogs.com/dengchaojie/p/4743358.html