博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITabBarController
阅读量:6967 次
发布时间:2019-06-27

本文共 1585 字,大约阅读时间需要 5 分钟。

UITabBarController

UITabBarControllerUINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换

1、         创建UITabBarController对象

    UITabBarController *tabbar = [[UITabBarController alloc]init];

2、         创建相应的子控制器

ViewController *vc = [[ViewController alloc] init];

vc.tabBarItem.title = @"主页";//设置标题

vc.tabBarItem.image = [UIImage imageNamed:@"1"];//设置图片

FirstViewController *first = [[FirstViewController alloc] init];

first.tabBarItem.title = @"消息";

first.tabBarItem.image = [UIImage imageNamed:@"2"];

3、         把子视图控制器加入UITabbarController

     tabbar.viewControllers = @[vc,first];

4、         设置windowrootViewControllerUITabbarController

self.window.rootViewController = tabbar

5、         设置tabbarVC选中第几个子视图:

[self.tabBarController setSelectedIndex:2];

6、         跳到某个指定的VC

UIViewController *vc = [self.tabBarController.viewControllers objectAtIndex:1];

[self.tabBarController setSelectedViewController:vc];

7、         获取当前选中的下标:

NSInteger index= self.tabBarController.selectedIndex;

8、         标签栏信息提示:

first.tabBarItem.badgeValue = @"3";

9、         设置选中的颜色(图片、文字)

 tabbar.tabBar.tintColor = [UIColor greenColor];

10、     设置背景图:

tabbar.tabBar.backgroundImage = [UIImage imageNamed:@"buy_ex"];

11、     设置背景色

tabbar.tabBar.barTintColor = [UIColor brownColor];

12、   置选中、未选中的图片

UIImage *image=[[UIImage imageNamed:@"3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage *image2 =[[UIImage imageNamed:@"tabbar_profile_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

second.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"个人" image:image selectedImage:image2];

 

转载于:https://www.cnblogs.com/niliu-star/p/4998886.html

你可能感兴趣的文章
实验五
查看>>
嵌入式Linux入门经典笔记
查看>>
leetcode29
查看>>
基于服务器的AAA作业(第二次)
查看>>
Objective-c——UI基础开发第十二天(相册展示)
查看>>
SQL中ISNULL的问题。
查看>>
利用map和stringstream数据流解题
查看>>
1.1.3 以类为单位的编程思想
查看>>
bzoj2440: [中山市选2011]完全平方数
查看>>
AC日记——中位数 洛谷 P1168
查看>>
Android 屏幕截图
查看>>
ubuntu 13.04 vim 的配置
查看>>
C++ 强制转换
查看>>
Python IDLE快捷键一览
查看>>
在通知栏上玩游戏,Steve iOS 游戏实现思路
查看>>
memcache---mongodb---redis比较
查看>>
C#之Action和Func的用法
查看>>
css transform旋转属性
查看>>
Python DB-API 2.0规范
查看>>
BOM
查看>>