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属性设置。

  • 相关阅读:
    分享一个流程实例运行时出现异常的恢复方案
    为什么要从事BPM开发
    分享两个BPM配置小技巧
    说说BPM数据表和日志表中几个状态字段的详细解释
    流程表单中js如何清空SheetUser控件数据?
    如何解决流程开发中SheetRadioButtonList页面取值问题
    把一个syn报文给rst掉
    linux io的cfq代码理解一
    xfs 的一些工具使用
    你知道这段代码为什么会段错误么?
  • 原文地址:https://www.cnblogs.com/ai-developers/p/4516697.html
Copyright © 2011-2022 走看看