zoukankan      html  css  js  c++  java
  • UITabbarController

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //1.创建Window
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        
        //a.初始化一个tabBar控制器
        UITabBarController *tb = [[UITabBarController alloc]init];
        //设置控制器为Window的根控制器
        self.window.rootViewController = tb;
        /***生成下边的工具栏叫  UITabBar  高度为49 (不变)***/
        
        //b.创建子控制器------- 通过storyboard 创建的子控制器
        UIStoryboard *storyb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        FirstItemViewController *c1 = [storyb instantiateViewControllerWithIdentifier:@"FirstItemViewController"];
          [self setAttrbutesWith:c1 title:@"消息" iConName:@"" backgroundColor:[UIColor lightGrayColor]];
        
        UIViewController *c2 = [[UIViewController alloc]init];
        [self setAttrbutesWith:c2 title:@"联系人" iConName:@"" backgroundColor:[UIColor brownColor]];
        
        UIViewController *c3 =[ [UIViewController alloc]init];
        [self setAttrbutesWith:c3 title:@"动态" iConName:@"" backgroundColor:[UIColor cyanColor]];
        
        UIViewController *c4 = [[UIViewController alloc]init];
        c4.view.backgroundColor = [UIColor grayColor];//背景颜色
        c4.tabBarItem.title = @"设置";//tabBarItem名称
        c4.tabBarItem.image = [UIImage imageNamed:@"Defualt Icon name"];//TabBarButton默认图标
        c4.tabBarItem.selectedImage = [UIImage imageNamed:@"selected Icon Name"];//TabBarButton的选中图标
        c4.tabBarItem.badgeValue = @"999+";//TabBarButton右上角的提示数字
        /****  这些默认图标、选中图标的尺寸 30 x 30  ****/
       
        
        //c.将创建的子控制器添加到TabBarController中
        /*方式一  展示的顺序和添加的顺序一致*/
        [tb addChildViewController:c1];
        [tb addChildViewController:c2];
        [tb addChildViewController:c3];
        [tb addChildViewController:c4];
        
        /*方式二  展示的顺序和添加的顺序一致*/
        //tb.viewControllers = @[c1,c2,c3,c4];
        
        
        //d. 设置UITabbar的默认选中项/*此属性在 加入了子子控制器后才能生效,并且不能下标越界*/
        tb.selectedIndex = 2;
       
       
        //e.设置tabBar的背景颜色
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 49)];
        backView.backgroundColor = [UIColor clearColor];
        backView.alpha = 0.5f;
        [tb.tabBar insertSubview:backView atIndex:0];
        tb.tabBar.opaque = YES;
        
        //2. 设置Window 为主窗口 并显示出来
        [self.window makeKeyAndVisible];
        
        return YES;
    }
    - (void)setAttrbutesWith:(UIViewController *)vc title:(NSString *)title iConName:(NSString *)imageName backgroundColor:(UIColor *)color
    {
        vc.view.backgroundColor = color;
        vc.tabBarItem.title = title;
        vc.tabBarItem.image = [UIImage imageNamed:imageName];
    }
  • 相关阅读:
    2-红帽RHEL 7起步
    1-了解开源共享精神
    5.pip安装时使用国内源,加快下载速度
    4. python-运算符(另类语法)
    海燕python学习目录,特别棒!
    1Python学习CentOS 7 Linux环境搭建
    2python脚本在window编辑后linux不能执行的问题
    3Python脚本在linux环境下头文件解释
    5G 频谱 新技术
    python -实现单例模式五种方法
  • 原文地址:https://www.cnblogs.com/Mgs1991/p/5337586.html
Copyright © 2011-2022 走看看