不解释,直接上代码:
#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//0,创建窗口
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
// //2,显示view方法2: 设置根控制器的方法显示,推荐使用控制器
MainViewController *addfirstview=[[MainViewController alloc]init];
[addfirstview.view setBackgroundColor:[UIColor yellowColor]];
self.window.rootViewController=addfirstview;
//在view上添加一个标签
UILabel *lable=[[UILabel alloc]init];
lable.text=@"通过代码添加:根控制器的方法显示";
[addfirstview.view addSubview:lable];
//显示窗口
[self.window makeKeyAndVisible];
return YES;
}