@interface
ShowLineView :
UIView
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextSetLineCap (context, kCGLineCapSquare ); // 设置线条样式
CGContextSetLineWidth (context, 0.2 ); // 设置线条粗细宽度
CGContextSetFillColorWithColor (context, [ UIColor redColor ]. CGColor ); // 设置颜色
CGContextBeginPath (context); // 开始一个起始路径
CGContextMoveToPoint (context, 10 , 30 ); // 起始点设置为 (0,0): 注意这是上下文对应区域中的相对坐标,
CGContextAddLineToPoint (context, 300 , 30 ); // 设置下一个坐标点
CGContextStrokePath (context); // 连接上面定义的坐标点
}
-----------------
-(
void
)showLine{
ShowLineView *view = [[ ShowLineView alloc ] initWithFrame : CGRectMake ( 0 , 30 , 320 , 100 )];
view. backgroundColor = [ UIColor cyanColor ];
[ self . view addSubview :view];
}
ShowLineView *view = [[ ShowLineView alloc ] initWithFrame : CGRectMake ( 0 , 30 , 320 , 100 )];
view. backgroundColor = [ UIColor cyanColor ];
[ self . view addSubview :view];
}