@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建根视图控制器
ViewController* rootViewController = [[ViewController alloc] init];
//创建自定义视图
MyView* view = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//用自定义视图替换系统默认视图
rootViewController.view = view;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.window.rootViewController = rootViewController;
return YES;
}
@end
@implementation MyView
- (void)drawRect:(CGRect)rect {
//填充白色背景
[[UIColor whiteColor] setFill];
UIRectFill(rect);
//自定义图形上下文
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint (context, 75, 10);
CGContextAddLineToPoint (context, 10, 150);
CGContextAddLineToPoint (context, 160, 150);
CGContextClosePath(context);
// 设置黑色描边参数
[[UIColor blackColor] setStroke];
// 设置红色条填充参数
[[UIColor redColor] setFill];
//绘制路径
CGContextDrawPath(context, kCGPathFillStroke);
}
@end