划线

来源:互联网 发布:卷皮淘宝网 编辑:程序博客网 时间:2024/04/27 19:44

继承UIView  重写drawRect方法

#import "CustomLine.h"


@implementation CustomLine


-(void)drawRect:(CGRect)rect

{

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetLineCap(context,kCGLineCapRound);

    CGContextSetLineWidth(context,2);//线宽

    CGContextSetAllowsAntialiasing(context,true);

    CGContextSetRGBStrokeColor(context,210.0/ 255.0,210.0/255.0 , 210.0/255.0 , 1.0);

    CGContextBeginPath(context);

    CGContextMoveToPoint(context,0, 10);//起点坐标

    CGContextAddLineToPoint(context,0,30);//坐标终点

    CGContextStrokePath(context);

}



其他类中调用

CustomLine *line = [[CustomLinealloc]init];

    line.backgroundColor = [UIColorwhiteColor];

    line.frame = CGRectMake(kScreenWidth/2 ,0, 10, view.frame.size.height);

    [view addSubview:line];


@end


0 0