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];
//----画三角形----