美文网首页
今天小弟来谈谈UITabBar

今天小弟来谈谈UITabBar

作者: 9bf19a4010ab | 来源:发表于2016-07-22 20:22 被阅读19次

UITabBarViewController(标签视图控制器) 用来管理没有层级关系的视图控制器
先来了解一下UITabBarViewController的创建
在Appdelegate.m文件中创建UITabBarViewController 首先一定要有多个视图控制器 然后创建UITabBarViewController对视图控制器进行管理
#import "AppDelegate.h"
#import "ViewController.h"
#import "FirstViewController.h"
#import "SecViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 创建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor whiteColor];
// 创建vc
ViewController *vc1 = [[ViewController alloc] init];
// 创建navigation
UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1];

FirstViewController *vc2 = [[FirstViewController alloc] init];
UINavigationController *navigation2 = [[UINavigationController alloc] initWithRootViewController:vc2];

SecViewController *vc3 = [[SecViewController alloc] init];
UINavigationController *navigation3 = [[UINavigationController alloc] initWithRootViewController:vc3];
// 创建UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// UITabBarController 有一个viewControllers属性 在这个属性里装navigation
tabBarController.viewControllers = @[navigation1, navigation2, navigation3];
// 将tabBarController设置为根视图控制器
self.window.rootViewController = tabBarController;
// 设置tabBar的标题 图片中 实心圆表示的就是tabBar的标题:
navigation1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:nil tag:100];
return YES;
}
// 如图中空心圆箭头所指就是
self.navigationItem.title = @"资讯";
DFC19D47-AA8A-4059-A77B-188505566593.png
// 设置tabBar的角标
navigation1.tabBarItem.badgeValue = @"10";
// 设置tabBar的颜色
tabBarController.tabBar.barTintColor = [UIColor cyanColor];
// 设置tabBar中元素的颜色
tabBarController.tabBar.tintColor = [UIColor blueColor];

忘了说tabBar的高度是49 而且tabBar数组中的元素一般不会大于5个

相关文章

  • 今天小弟来谈谈UITabBar

    UITabBarViewController(标签视图控制器) 用来管理没有层级关系的视图控制器先来了解一下UIT...

  • 来,谈谈今天~

    傍晚时分,下午复习了一部分初级会计考试内容,稍有疲惫,看着课本画画记记。习惯性地拿起手机看看微信信息,看到...

  • 今天来谈谈社交

    人是社交生物。社交的意思就是社会交往。社会的意思就是很多人之间形成的各种关系网。在关系网中有家庭关系,买卖关系,雇...

  • 今天来谈谈湿

    好多老百姓看病的时候会问,为啥我乏力我是不是有肾虚?当我回答病人,你没有肾虚,而是湿气重的时候,病人往往不能理...

  • 今天来谈谈经验

    我记得小时侯,对什么东西都会充满好奇,喜欢摸摸这儿,看看那儿。 但是很多东西并不能够去尝试。曾经我对电产生了极大的...

  • 今天来谈谈“死亡

    众所周知,死亡是每一个人的终点站。绝大多数的人都是害怕死亡的。坂田银时 在《银魂 》中说:“人类害怕的事情有两个,...

  • 今天来谈谈学习

    单位搞调查,作为谢礼给了一个14根的孔明锁,以前我对这种益智类的玩具是敬而远之的,但是不知是通了那一根筋突然觉得:...

  • 今天来谈谈“送礼”

    001 能收到别人送来的礼物是很开心的一件事,尤其是第一次见面的时候,这会让对方感觉到很被重视,也更愿意与你交往。...

  • 今天来谈谈爱

    文|一朵青莲 520,521,最近两天都是谈爱的日子,我更喜欢521,我爱你,今天就来谈谈爱! 我想谈的是关于爱孩...

  • iOS显示和隐藏TabBar

    显示UITabBar 隐藏UITabBar

网友评论

      本文标题:今天小弟来谈谈UITabBar

      本文链接:https://www.haomeiwen.com/subject/akbijttx.html