zoukankan      html  css  js  c++  java
  • 基本组件的使用——UITabBarController

    和UINavigationController的作用差不多,UITabBarController也可以在多个UIViewController中切换

    这个控件的使用相对简单,只需要为该控件的viewControllers添加引用就可以了,然后将根视图控制器设置为该控件即可。如下图所示。

    image

    最终效果:

    UITabBarController

    实现代码:

    代码在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中完成

    //创建第一个视图控制器并添加系统按钮样式
        UIViewController *firstViewController = [[UIViewController alloc] init];
        firstViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1];
        firstViewController.view.backgroundColor = [UIColor brownColor];
        
        //创建第二个视图控制器并添加系统按钮样式 
        UIViewController *secondViewController = [[UIViewController alloc] init];
        secondViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2];
        secondViewController.view.backgroundColor = [UIColor yellowColor];
        
        //初始化UITabBarController
        self.tabController = [[UITabBarController alloc] init];
        
        //添加TabBarController对两个视图对引用
        self.tabController.viewControllers = @[firstViewController, secondViewController];
        
        //设置根视图控制器为UITabBarController
        self.window.rootViewController = self.tabController;

    代码很简单,就是实例化了两个UIViewController,然后使用self.tabController.viewControllers添加两个引用。

    另外两个TabBarItem都是使用系统的样式。TabBarItem属性UITabBarItem类。如果需要自定义这两个按钮,

    可以分别设置TabBarItem的图片属性:下图红圈处image

    按钮文字则可以直接使用UIViewController的title属性设置。

  • 相关阅读:
    iOS开发 数据缓存-数据库
    我是程序猿,我自豪,我骄傲!嗷嗷嗷!
    【Golang】练习-复制文件
    【Golang】练习-读取目录下的文件并按时间进行排序
    【Golang】练习 tailf 简单模拟
    【Golang】基础-切片 for 循环删除元素
    【Golang】基础-操作 csv 文件
    【Golang】Godoc 或者第三方 plugins 插件介绍
    【Golang】类型转换之 cast 包
    【Golang】解决 go get下载包慢或者失败的问题
  • 原文地址:https://www.cnblogs.com/ai-developers/p/4516697.html
Copyright © 2011-2022 走看看