UITabBarViewController

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    
    UIViewController *vc1 = [[UIViewController alloc]init];
    
    vc1.view.backgroundColor  =[UIColor redColor];
    
    vc1.tabBarItem.title = @"消息";
    
    vc1.tabBarItem.badgeValue = @"123";
    
    
    UIViewController *vc2 = [[UIViewController alloc]init];
    
    vc2.tabBarItem.title = @"联系人";
    
    vc2.tabBarItem.badgeValue = @"123";

    vc2.view.backgroundColor  =[UIColor greenColor];
    
    UIViewController *vc3 = [[UIViewController alloc]init];
    
    vc3.view.backgroundColor  =[UIColor grayColor];
    
    vc3.tabBarItem.title = @"动态";
    
    vc3.tabBarItem.badgeValue = @"123";
    
    UIViewController *vc4 = [[UIViewController alloc]init];
    
    vc4.tabBarItem.title = @"设置";
    
    vc4.tabBarItem.badgeValue = @"123";
    
    vc4.view.backgroundColor  =[UIColor blueColor];
    
    //两种方式
//    tabBarController.viewControllers = @[vc1,vc2,vc3,vc4];
    
    [tabBarController addChildViewController:vc1];
    [tabBarController addChildViewController:vc2];

    [tabBarController addChildViewController:vc3];
    [tabBarController addChildViewController:vc4];


    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor  =[UIColor redColor];
    
    self.window.rootViewController = tabBarController;
    
    [self.window makeKeyAndVisible];
    
    
    return YES;
}

你可能感兴趣的:(UITabBarViewController)