//绘制多图形(继承UIView)
- (void)drawRect:(CGRect)rect
{
UIColor *color = [UIColor redColor];
[color set];
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 5.0;
//创建多边形
[path moveToPoint:CGPointMake(100, 0)];
//画线
[path addLineToPoint:CGPointMake(200, 40)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40, 140)];
[path addLineToPoint:CGPointMake(0, 40)];
//封口
[path closePath];
//渲染
[path fill];
}
//绘制圆角矩形
- (void)drawRect:(CGRect)rect
{
UIColor *color = [UIColor redColor];
[color set];
//圆角矩形
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 50, 80, 80) cornerRadius:10];
path.lineWidth = 5.0;
//渲染
[path fill];
//练习:用该方法 创建一个 空心的 圆角的矩形。
//圆角矩形
UIBezierPath *path1 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 180, 180, 80) cornerRadius:10];
path1.lineWidth = 5.0;
//渲染
[path1 stroke];
}
//加载图形(继承UIViewController
)
- (void)viewDidLoad
{
[super viewDidLoad];
TRMyView *myView = [[TRMyView alloc] initWithFrame:self.view.frame];
[self.view addSubview:myView];
}
//加载到主窗口(AppDelegate)
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[TRRootViewController alloc] init];