用代码实现UITabBarController

作者: MWY | 来源:发表于2015-11-16 20:28 被阅读150次
     // 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;
        
    

    相关文章

      网友评论

        本文标题:用代码实现UITabBarController

        本文链接:https://www.haomeiwen.com/subject/bjwkhttx.html