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的更多相关文章
随机推荐
- slf4j logback pom
pom: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding&g ...
- C++ shared_ptr
晕晕乎乎,其他的再补充 1.shared_ptr 主要是为了方便管理内存而存在的,C++程序中不会再出现new 和 delete,内存的分配和析构全部由shared_ptr进行管理 2.当程序中对某个 ...
- HDU - 5999 The Third Cup is Free 贪心 简单题
The Third Cup is Free Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 洛谷——P1231 教辅的组成
P1231 教辅的组成 题目背景 滚粗了的HansBug在收拾旧语文书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本语文书里面发现了一本答案,然而他却明明记得这书应该还包含一份练习 ...
- 用户管理和FTP服务配置
批量创建用户 python脚本:creuser.py import osulist=open('usernames','r')for x in ulist: cmd="useradd -g ...
- python opencv3 滤波器 卷积核
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np from sc ...
- [BZOJ5291][BJOI2018]链上二次求和(线段树)
感觉自己做的麻烦了,但常数似乎不算差.(只是Luogu最慢的点不到2s本地要跑10+s) 感觉我的想法是最自然的,但不明白为什么网上似乎找不到这种做法.(不过当然所有的做法都是分类大讨论,而我的方法手 ...
- [Luogu5106]dkw的lcm
https://minamoto.blog.luogu.org/solution-p5106 容易想到枚举质因子及其次数计算其贡献,容斥计算$\varphi(p^i)$的次方数. #include&l ...
- 【dijkstra优化/次短路径】POJ3255-Roadblocks
[题目大意] 给出一张无向图,求出从源点到终点的次短边. [思路] 先来谈谈Dijkstra的优化.对于每次寻找到当前为访问过的点中距离最短的那一个,运用优先队列进行优化,避免全部扫描,每更新一个点的 ...
- HDU 5683 zxa and xor 暴力模拟
zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...