需求
1.畫一個倒三角,一般用於導航欄點擊彈出選項
效果
如下圖
這裏是實現效果,畫出效果,具體可調
代碼實現
添加一個UIImage的分類 ,在分類中寫如下代碼
+ (UIImage *)triangleImageWithSize:(CGSize)size tintColor:(UIColor *)tintColor{
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(size.width/2,size.height)];
[path addLineToPoint:CGPointMake(size.width, 0)];
[path closePath];
CGContextSetFillColorWithColor(ctx, tintColor.CGColor);
[path fill];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}