建立控制器

    // 普通控制器
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的更多相关文章

随机推荐

  1. Educational Codeforces Round 9 D - Longest Subsequence

    D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...

  2. Linq To Sql 使用初探

    最近有数据处理需要,就是那种从数据库中把数据取出来 ,对其中的部分字段做一些处理再吐回去的工作,从同事那里学习到了,这中活最适合使用 Linq to Sql 这种方式,不用搭建框架,不用自建实体,直接 ...

  3. 14个你可能不知道的JavaScript调试技巧

    调试JS的时候,搜索一下这个标题

  4. Moo University - Financial Aid POJ 2010 优先队列(最大堆)

    题目:http://poj.org/problem?id=2010 题目大意: 奶牛上大学.因为经济问题,每头奶牛都需要一定的补助需求,学校会提供一定的资金用于补助 每头牛都有自己的分数,学校招收的名 ...

  5. redis 多实例 连接 加密码

    =启动多个redis实例= #redis-server/usr/local/redis/redis6370.conf #redis-server/usr/local/redis/redis6371.c ...

  6. Java Maven:spring boot + Mybatis连接MySQL,通用mapper的增删改查,映射实现多表查询

    1. MySQL自带库test添加表user.role 角色表role 用户表user 2. 添加依赖,配置属性 相关依赖:百度即可,此处略 application.properties spring ...

  7. Html的学习随笔

    在<head>的<style>中定义样式,有#号,比如#header就是定义一种名为header的样式,后面用id=header来调用:而无#号,比如直接就是header,那后 ...

  8. MYSQL用户操作管理大杂烩

    一.创建用户 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指定该 ...

  9. 五子棋游戏 canvas 事件 边界检测

    //有一定基础的人才能看得懂 <!doctype html><html lang="en"> <head> <meta charset=& ...

  10. Python threads synchronization: Locks, RLocks, Semaphores, Conditions, Events and Queues(Forwarding)

    This article describes the Python threading synchronization mechanisms in details. We are going to s ...