自定义View画一条线

#import "PublishContextView.h"

@implementation PublishContextView

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    CGContextRef context=UIGraphicsGetCurrentContext();//获得当前上图形线文
    CGContextMoveToPoint(context, 0, rect.size.height);//设置起点
    CGContextAddLineToPoint(context, rect.size.width, rect.size.height);//添加一条线
    const CGFloat *RGBs=CGColorGetComponents([UIColor colorWithRed:216.0/255.0 green:216.0/255.0 blue:216.0/255.0 alpha:0.9].CGColor);
    CGContextSetRGBStrokeColor(context, RGBs[0], RGBs[1], RGBs[2], 1.0f);
    CGContextStrokePath(context);
}

@end
原文地址:https://www.cnblogs.com/code-changeworld/p/4713588.html