iOSUITabBarController 和 UINavigationController

用代码实现UITabBarController

2015-11-16  本文已影响150人  MWY
 // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    
    HotShowingController *hotShowingController = [[HotShowingController alloc] init];
    SearchController *searchController = [[SearchController alloc] init];
    ListController *listController = [[ListController alloc] init];
    
    [tabBarController setViewControllers:@[hotShowingController, searchController, listController]];
    
    //UITabBar
    UITabBar *taBar = tabBarController.tabBar;
    UITabBarItem *tabBarItem1 = [taBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [taBar.items objectAtIndex:1];
    UITabBarItem *tabBarItem3 = [taBar.items objectAtIndex:2];
    tabBarItem1.title = @"热映";
    tabBarItem1.image = [UIImage imageNamed:@"movies"];
    tabBarItem2.title = @"搜索";
    tabBarItem2.image = [UIImage imageNamed:@"search"];
    tabBarItem3.title = @"榜单";
    tabBarItem3.image = [UIImage imageNamed:@"list"];

    self.window.rootViewController = tabBarController;
    
    [self.window makeKeyAndVisible];
    return YES;
    
上一篇下一篇

猜你喜欢

热点阅读