iOS开发学习笔记(OC语言)——底部tab栏

SceneDelegate.m

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    
    UIWindowScene *windowScene = (UIWindowScene *)scene;
    self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
    self.window.frame = windowScene.coordinateSpace.bounds;
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    
    UIViewController *controller1 = [[UIViewController alloc] init];
    controller1.view.backgroundColor = [UIColor redColor];
    controller1.tabBarItem.title = @"Tab1";
    controller1.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/home"];
    controller1.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/home_selected"];
    
    UIViewController *controller2 = [[UIViewController alloc] init];
    controller2.view.backgroundColor = [UIColor yellowColor];
    controller2.tabBarItem.title = @"Tab2";
    controller2.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/video"];
    controller2.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/video_selected"];
    
    UIViewController *controller3 = [[UIViewController alloc] init];
    controller3.view.backgroundColor = [UIColor blueColor];
    controller3.tabBarItem.title = @"Tab3";
    controller3.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/like"];
    controller3.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/like_selected"];
    
    UIViewController *controller4 = [[UIViewController alloc] init];
    controller4.view.backgroundColor = [UIColor greenColor];
    controller4.tabBarItem.title = @"Tab4";
    controller4.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/page"];
    controller4.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/page_selected"];
    
    [tabBarController setViewControllers: @[controller1, controller2, controller3, controller4]];
    
    tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
        
    self.window.rootViewController = tabBarController;
    [self.window makeKeyAndVisible];
}
posted @   观海云不远  阅读(251)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
历史上的今天:
2016-02-14 Android学习笔记之,调用系统图库,添加自定义字体,屏幕截图
点击右上角即可分享
微信分享提示