现在的位置: 首页 > 综合 > 正文

iOS 画线

2017年12月09日 ⁄ 综合 ⁄ 共 733字 ⁄ 字号 评论关闭
@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];

}






抱歉!评论已关闭.