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

iOS在view中绘制不规则图形

2017-07-13 12:04 1776 查看
iOS绘制不规则图形,可以设置各个经过的点,以及是否有边框,是否有填充色等。

//----画三角形----
UIGraphicsBeginImageContext(cellView.bounds.size);
//设置背景颜色
[[UIColor clearColor]set];
UIRectFill([cellView bounds]);
//拿到当前视图准备好的画板
CGContextRef context = UIGraphicsGetCurrentContext();
//利用path进行绘制三角形
CGContextBeginPath(context);//标记
CGContextMoveToPoint(context, 71, 36);//设置起点
CGContextAddLineToPoint(context, 58, 44);//经过的点,可以多写几个点
CGContextAddLineToPoint(context, 71, 52);//重点
//    CGContextClosePath(context);//路径结束标志,不写默认封闭
[[UIColor whiteColor] setFill]; //设置填充色
[[UIColor lightGrayColor] setStroke]; //设置边框颜色
CGContextDrawPath(context, kCGPathFillStroke);//绘制路径path
//从Context中获取图像,并显示在界面上
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *gifTriangleView = [[UIImageView alloc] initWithImage:img];
[cellView addSubview:gifTriangleView];
//----画三角形----
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios