1 #import "AppDelegate.h" 2 #import "FirstViewController.h" 3 #import "SecondViewController.h" 4 5 @interface AppDelegate () 6 7 @end 8 9 @implementation AppDelegate 10 11 12 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 13 14 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 15 self.window.backgroundColor = [UIColor whiteColor]; 16 17 //创建子控制器 18 FirstViewController *first = [[FirstViewController alloc] init]; 19 first.tabBarItem.title = @"主页"; 20 first.tabBarItem.image = [UIImage imageNamed:@"home.png"]; 21 first.tabBarItem.badgeValue = @"123"; 22 23 SecondViewController *second = [[SecondViewController alloc] init]; 24 second.tabBarItem.title = @"设置"; 25 second.tabBarItem.image = [UIImage imageNamed:@"setting.png"]; 26 27 //创建标签控制器 28 UITabBarController *tabCtr = [[UITabBarController alloc] init]; 29 30 NSArray *viewControllerArr = [NSArray arrayWithObjects:first,second, nil]; 31 32 tabCtr.viewControllers = viewControllerArr; 33 34 self.window.rootViewController = tabCtr; 35 36 [self.window makeKeyAndVisible]; 37 38 return YES; 39 } 40 41 42 #import "FirstViewController.h" 43 44 @interface FirstViewController () 45 46 @end 47 48 @implementation FirstViewController 49 50 - (void)viewDidLoad { 51 [super viewDidLoad]; 52 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, self.view.frame.size.width-200, 50)]; 53 label.backgroundColor = [UIColor whiteColor]; 54 label.textAlignment = NSTextAlignmentCenter; 55 label.text = @"第一个视图"; 56 [self.view addSubview:label]; 57 58 self.view.backgroundColor = [UIColor cyanColor]; 59 } 60 61 - (void)didReceiveMemoryWarning { 62 [super didReceiveMemoryWarning]; 63 // Dispose of any resources that can be recreated. 64 } 65 66 @end 67 68 69 70 #import "SecondViewController.h" 71 72 @interface SecondViewController () 73 74 @end 75 76 @implementation SecondViewController 77 78 - (void)viewDidLoad { 79 [super viewDidLoad]; 80 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, self.view.frame.size.width-200, 50)]; 81 label.backgroundColor = [UIColor whiteColor]; 82 label.textAlignment = NSTextAlignmentCenter; 83 label.text = @"第二个视图"; 84 [self.view addSubview:label]; 85 86 self.view.backgroundColor = [UIColor purpleColor]; 87 } 88 89 - (void)didReceiveMemoryWarning { 90 [super didReceiveMemoryWarning]; 91 // Dispose of any resources that can be recreated. 92 } 93 94 @end
iOS UI-标签控制器(UITabBarController)
原文:http://www.cnblogs.com/oc-bowen/p/5092601.html