您的位置:首页 > 移动开发 > IOS开发

iOS画线

2015-07-09 17:04 309 查看

iOS画线(直线,折线,多个线段)

UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(5, 44+HEIGHT_ADJUST_IOS7_BAR+5, SCREENSIZE.width-10, 175-49)];
imageView.backgroundColor = [UIColor whiteColor];
self.view.backgroundColor = COLOR_HEX_RGB(0xefefef);
[self.view addSubview:imageView];
[self.view sendSubviewToBack:imageView];

UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 0.1);  //线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.6, 0.6, 0.6, 1.0);  //颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 15, 95-49);  //起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), SCREENSIZE.width-15, 95-49);   //如果是折线,一直写下去,就不停的拐弯。
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), SCREENSIZE.width-15, 135-49);   //另一个起点坐标,重新开始了一条线
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 15, 135-49);   //终点坐标

CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: