UI_UITabBarController
建立控制器
// 普通控制器
GroupViewController *groupVC = [[GroupViewController alloc] init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fourthVC = [[FourthViewController alloc] init];
// 导航栏控制器
UINavigationController *groupNC = [[UINavigationController alloc] initWithRootViewController:groupVC];
UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:secondVC];
UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourthVC];```
@interface AppDelegate () <UITabBarControllerDelegate>
// tabBarVC 控制器
UITabBarController *tabBarVC = [[UITabBarController alloc] init];
// 设置 tabBarVC 代理(先遵守协议)
tabBarVC.delegate = self;
// 设置 tabBar 默认选中的控制器
tabBarVC.selectedIndex = 1;
// 设置 tabBarVC 管理(包括)的控制器
tabBarVC.viewControllers = @[groupNC, secondNC, thirdNC, fourthNC, uiVC1, uiVC2, uiVC3];
// 自己定义样式 tabBarItem(选中颜色)注意是那种控制器
groupNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"活动" image:[UIImage imageNamed:@"activity"] selectedImage:[UIImage imageNamed:@"微信"]];
// 显示右上角 小圈圈
groupNC.tabBarItem.badgeValue = @"10";
secondNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"影院" image:[UIImage imageNamed:@"cinema"] selectedImage:[UIImage imageNamed:@"通讯录"]];
thirdNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"电影" image:[UIImage imageNamed:@"movie"] selectedImage:[UIImage imageNamed:@"发现"]];
fourthNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"user"] selectedImage:[UIImage imageNamed:@"我"]];
// 设置整个 tabBar
// 颜色(和样式冲突)
tabBarVC.tabBar.barTintColor = [UIColor yellowColor];
// 样式(和颜色冲突)
// tabBarVC.tabBar.barStyle = UIBarStyleBlack;
// 字体颜色
[tabBarVC.tabBar setTintColor:[UIColor greenColor]];
#pragma mark - 选择 tabBar 所控制的控制器,会运行的方法(每次都会运行)
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
if (index == 3) {
NSLog(@"four");
}
if (tabBarController.selectedIndex == 2) {
NSLog(@"three");
}
}
#pragma mark - 控制 tabBar 能否够点击
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
return YES;
}
// 获取到全部的 UINavigationBar(project里面全部)
[[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
UI_UITabBarController的更多相关文章
随机推荐
- thinkphp中I()方法的详解
I('post.email','','email'); int boolean float validate_regexp validate_url validate_email validate_i ...
- (一)预定义宏、__func__、_Pragma、变长参数宏定义以及__VA_ARGS__
作为第一篇,首先要说一下C++11与C99的兼容性. C++11将 对以下这些C99特性的支持 都纳入新标准中: 1) C99中的预定义宏 2) __func__预定义标识符 3) _Pragma操作 ...
- Top 5 SSH Clients for Windows (Alternatives of PuTTY)
这篇博文列举了可以替代putty的5个工具,有些实现了putty没有实现的一些功能.如下: PuTTy is the most popular SSH clients for Windows-base ...
- [leetcode trie]208. Implement Trie (Prefix Tree)
实现一个字典树 class Trie(object): def __init__(self): self.root = TrieNode() def insert(self, word): cur = ...
- 1002 A+B for Polynomials (25)(25 point(s))
problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...
- 机器学习之路:python 网格搜索 并行搜索 GridSearchCV 模型检验方法
git:https://github.com/linyi0604/MachineLearning 如何确定一个模型应该使用哪种参数? k折交叉验证: 将样本分成k份 每次取其中一份做测试数据 其他做训 ...
- codevs 2577 医院设置
2577 医院设置 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 设有一棵二叉树,如下图 其中,圈中数字表示结点居民的人口.圈边 ...
- [WC2018]州区划分(状压DP+FWT/FMT)
很裸的子集反演模板题,套上一些莫名其妙的外衣. 先预处理每个集合是否合法,再作显然的状压DP.然后发现可以写成子集反演的形式,直接套模板即可. 子集反演可以看这里. 子集反演的过程就是多设一维代表集合 ...
- POJ 2778 DNA Sequence(AC自动机+矩阵)
[题目链接] http://poj.org/problem?id=2778 [题目大意] 给出一些字符串,求不包含这些字符串的长度为n的字符串的数量 [题解] 我们将所有串插入自动机计算match,对 ...
- vijos p1881 线段树
题意:点我 我就想问,现在换代码风格还来得及吗? 2015-05-19:线段树进一步加强,看来不用换风格了 维护左右节点左右端颜色和长度即可 #include<cstdio> #inclu ...