我想創建一個UIBezierPath在UIView類別中使用的三角形。但三角形沒有被顯示。也得到:CGContextSetFillColorWithColor。所以我的問題是如何使三角形或任何使用UIView類別的路徑。 Demo Project在UIView類別中創建一個UIBezierPath。不顯示
#import "UIView+Bubble.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (Bubble)
+(UIView *)makeBubble{
UIView *customView = [[UIView alloc] init];
customView.frame=CGRectMake(0, 0, 320, 500);
UIBezierPath *triangle = [UIBezierPath bezierPath];
[triangle moveToPoint:CGPointMake(100, 0)];
[triangle addLineToPoint:CGPointMake(0, 100)];
[triangle addLineToPoint:CGPointMake(200, 100)];
[triangle closePath];
[[UIColor blackColor] setFill];
[triangle fill];
customView.layer.shadowPath = [triangle CGPath];
return customView;
}
@end
在ViewController.m使用它,如: -
- (void)viewDidLoad
{
UIView *helpBubble=[UIView makeBubble];
[self.view addSubview:helpBubble];
}
@ x4h1d-如何根據cgrect給UIGraphicsBeginImageContextWithOptions動態。 – iOS
@John,請參閱編輯部分。 – x4h1d
@ x4h1d-非常感謝。 – iOS