zoukankan      html  css  js  c++  java
  • IOS UI TabBar标签栏的使用

    IOS标签栏起导航作用,标签栏就是像微信下面的四个小小标签,分别是“微信”、“通讯录”、“发现”、“我”,使用标签可以使你的app瞬间高大一些,不再是单纯的点击按钮一连串的跳转。
    而且Ios的标签栏很容易实现,很少的代码就能实现,本例设四个标签,简单基本使用很简单,所以不多说,看看代码和注释就差不多能懂
    step1:先是将四个页面创建放进UINavigationController,虽然代码量不算小,但是都是一样的,只是写四次而已,对了,忘了说是写在AppDelegate里面的第一个方法里的
    
     //显示第一个界面, 加入导航控制器
        ViewController *mvc = [[ViewController alloc] init];
        //设置title显示导航条上
        mvc.title = @"主界面";
        mvc.tabBarItem.image = [UIImage imageNamed:@"tab_0.png"];
    
        //创建导航控制器, 让导航控制器管理mvc
        //  设置一个普通视图控制器作为根视图控制器
        UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:mvc];
    
        //创建第二个界面
        ContactsViewController *cvc = [[ContactsViewController alloc] init];
        cvc.title = @"联系人";
        cvc.tabBarItem.image = [UIImage imageNamed:@"tab_1.png"];
        UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:cvc];
    
        //第三个界面
        DynamicViewController *dvc = [[DynamicViewController alloc] init];
        dvc.title = @"动态";
        dvc.tabBarItem.image = [UIImage imageNamed:@"tab_2.png"];
        UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:dvc];
    
        //第四个界面
        SettingViewController *svc = [[SettingViewController alloc] init];
        svc.title = @"设置";
        svc.tabBarItem.image = [UIImage imageNamed:@"tab_3.png"];
        UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:svc];
    
    step2:创建标签栏,将上面四个UINavigationController放进去,然后设置一些简单的属性就完成了,顺便设置个背景色也是可以的
    
     //创建标签栏
        UITabBarController *tbc = [[UITabBarController alloc] init];
        tbc.viewControllers = @[nc1,nc2,nc3,nc4];
    
        self.window.rootViewController = tbc;
    
        //标签栏默认高度49
        //[tbc.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
    
        //设置选中的颜色
        tbc.tabBar.tintColor = [UIColor greenColor];
    
        self.window.backgroundColor=[UIColor colorWithRed:266/255.0 green:266/255.0 blue:266/255.0 alpha:1];
    

    运行图片就是这样的!

    这里写图片描述

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Centos服务器搭建(3)——安装maven
    Centos服务器搭建(2)——安装tomcat
    Centos服务器搭建(1)——安装jdk
    mysql主从复制
    Json中返回换行符处理
    github pages 绑定域名
    SharePoint学习笔记——子页面
    SharePoint学习笔记——母版页
    SSH+Oracle的整合(SSH与Oracle整合坑巨多)
    SSH整合做CRUD(大神老师整理)
  • 原文地址:https://www.cnblogs.com/yuqingzhude/p/4836543.html
Copyright © 2011-2022 走看看