iOS 画线

来源:互联网 发布:mac 上传图片失败 反复 编辑:程序博客网 时间:2024/05/22 15:46
@interface ShowLineView : UIView

-(void)drawRect:(CGRect)rect{

    
CGContextRef context = UIGraphicsGetCurrentContext();
    
CGContextSetLineCap(context, kCGLineCapSquare);//设置线条样式
    
CGContextSetLineWidth(context, 0.2);    //设置线条粗细宽度
    
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);   //设置颜色
    
CGContextBeginPath(context);    //开始一个起始路径
    
CGContextMoveToPoint(context, 1030);  //起始点设置为(0,0):注意这是上下文对应区域中的相对坐标,
    
CGContextAddLineToPoint(context, 30030); //设置下一个坐标点
    
CGContextStrokePath(context);  //连接上面定义的坐标点
}
-----------------
-(void)showLine{

    
ShowLineView *view = [[ShowLineView allocinitWithFrame:CGRectMake(030320100)];
    view.
backgroundColor = [UIColor cyanColor];
    [
self.view addSubview:view];

}





0 0
原创粉丝点击