iOS结合导航控制器和标签栏控制器
<span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="objc">- (void)initTabBar
{
// 初始化主页
HomePageViewController *homePage = [[HomePageViewController alloc]init];
UINavigationController *homePageNav = [[UINavigationController alloc]initWithRootViewController:homePage]; // 推断是否存在用户存储的城市
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
if (![userDefault objectForKey:@"cityDic"]) {
CitySelectionViewController *citySelection = [[CitySelectionViewController alloc]init];
[homePageNav pushViewController:citySelection animated:YES];
}
// 设置主页-TabBar
UITabBarItem *itemHomePage= [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.png"] scaledToSize:CGSizeMake(25, 25)] tag:0];
[itemHomePage setFinishedSelectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.jpg"] scaledToSize:CGSizeMake(25, 25)] withFinishedUnselectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-2.jpg"] scaledToSize:CGSizeMake(25, 25)]];
homePageNav.tabBarItem=itemHomePage;
[itemHomePage setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NAVBACKGROUNDCOLOR,UITextAttributeTextColor, nil] forState:UIControlStateSelected]; if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO([NSString stringWithFormat:@"7.0"])) {
[homePageNav.navigationBar setBarTintColor:NAVBACKGROUNDCOLOR];
}else
{
[homePageNav.navigationBar setTintColor:NAVBACKGROUNDCOLOR];
}
homePageNav.navigationBar.translucent = NO; // 初始化我的购物车
ShoppingCartViewController *shoppingCart = [[ShoppingCartViewController alloc]init];
UINavigationController *shoppingCartNav = [[UINavigationController alloc]initWithRootViewController:shoppingCart]; // 设置购物车-TabBar
UITabBarItem *itemShoppingCart= [[UITabBarItem alloc] initWithTitle:@"我的购物车" image:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.png"] scaledToSize:CGSizeMake(25, 25)] tag:0];
[itemShoppingCart setFinishedSelectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.jpg"] scaledToSize:CGSizeMake(25, 25)] withFinishedUnselectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-2.jpg"] scaledToSize:CGSizeMake(25, 25)]];
shoppingCartNav.tabBarItem=itemShoppingCart;
[itemShoppingCart setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NAVBACKGROUNDCOLOR,UITextAttributeTextColor, nil] forState:UIControlStateSelected]; if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO([NSString stringWithFormat:@"7.0"])) {
[shoppingCartNav.navigationBar setBarTintColor:NAVBACKGROUNDCOLOR];
}else
{
[shoppingCartNav.navigationBar setTintColor:NAVBACKGROUNDCOLOR];
}
shoppingCartNav.navigationBar.translucent = NO; // 初始化我的汇众
IndividualCenterViewController *individualCenter = [[IndividualCenterViewController alloc]init];
UINavigationController *individualCenterNav = [[UINavigationController alloc]initWithRootViewController:individualCenter]; // 设置汇众-TabBar
UITabBarItem *itemindividualCenter= [[UITabBarItem alloc] initWithTitle:@"我的幸福家" image:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.png"] scaledToSize:CGSizeMake(25, 25)] tag:0];
[itemindividualCenter setFinishedSelectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-1.jpg"] scaledToSize:CGSizeMake(25, 25)] withFinishedUnselectedImage:[UIImage imageWithImage:[UIImage imageNamed:@"1-2.jpg"] scaledToSize:CGSizeMake(25, 25)]];
individualCenterNav.tabBarItem=itemindividualCenter;
[itemindividualCenter setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NAVBACKGROUNDCOLOR,UITextAttributeTextColor, nil] forState:UIControlStateSelected]; if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO([NSString stringWithFormat:@"7.0"])) {
[individualCenterNav.navigationBar setBarTintColor:NAVBACKGROUNDCOLOR];
}else
{
[individualCenterNav.navigationBar setTintColor:NAVBACKGROUNDCOLOR];
}
individualCenterNav.navigationBar.translucent = NO; self.tabBar = [[UITabBarController alloc] init];
[[UITabBar appearance] setBackgroundImage:[UIImage setBackgroundImageByColor:COLOR(255, 255, 255, 1) withFrame:RectWithPara(0, 0, SCREEN_WIDTH, 44)]]; // 设置UITabBar背景图片
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageWithTint:COLOR(235, 235, 235, 1)]];
self.tabBar.viewControllers = [NSArray arrayWithObjects:homePageNav,shoppingCartNav,individualCenterNav, nil];
}
<span style="font-family: Arial, Helvetica, sans-serif;">在程序启动时设置根控制器为 tabbar,例如以下</span>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
[self
initTabBar];
self.window.rootViewController =
self.tabBar;
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
return
YES;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
iOS结合导航控制器和标签栏控制器的更多相关文章
- 导航栏控制器和标签栏控制器(UINavigationController和UITabBarController)混用
很多时候,在UI设计方面同时需要使用导航控制器和标签栏控制器,这时,需要掌握如何设计结合使用这两种不同控制器.比如手机QQ,程序有三个标签 栏(分别为消息.联系人.动态),同时在选择某个联系人或者会话 ...
- iOS:给标签栏控制器的UITabbarItem添加点击动效
一.介绍 现在很多app,附带很炫的点击效果,让用户享受到非常棒的体验,例如动画.渐变.音效等. 当然,市面上大多数app的标签栏点击还是挺中规中矩的,只是切换图片而已.然而,这个是可以优化的,附带点 ...
- IOS之导航控制器
UINavigationController是用于构建分层应用程序的主要工具,主要采用栈形式来实现视图.任何类型的视图控制器都可放入栈中.在设计导航控制器时需要指定根视图即用户看到的第一个视图.根视图 ...
- iOS:切换视图的第三种方式:UITabBarController标签栏控制器
UITabBarController:标签栏控制器 •通过设置viewControllers属性或者addChildViewController方法可以添加子控制器 –NSArray *viewCon ...
- IOS开发之视图和视图控制器
视图(View), 视图控制器(ViewController)是IOS开发UI部分比较重要的东西.在学习视图这一块的东西的时候,感觉和Java Swing中的Panel差不多.在UIKit框架中都有一 ...
- 标签栏控制器(UITabBarController)
一.标签栏控制器基础 1.绪论 a.一个标签栏是一个独立的界面对象,它经常与一个视图控制器(UITabBarController是UIViewController的子类)一起使用. b.一个标签栏项目 ...
- iOS:自定义工具栏、导航栏、标签栏
工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...
- UITabBarController 标签栏控制器
接上篇导航控制器UINavigationController 接下来是UITabBarController 标签栏控制器 先来看一下UITabBarController的结构 从图上可以看出控制器分为 ...
- iOS: 状态栏、导航栏、标签栏、工具栏
三种项目栏总结: 工具栏:UIToolBar 导航栏:UINavigationBar 标签栏:UITabBar UIToolBar的按钮单元为:UIBarButtonItem UINavigati ...
随机推荐
- 用C语言写解释器(一)——我们的目标
声明 为提高教学质量,我所在的学院正在筹划编写C语言教材.<用C语言写解释器>系列文章经整理后将收入书中"综合实验"一章.因此该系列的文章主要阅读对象定为刚学完C语言的 ...
- LINUX专题之操作系统字符集
原创作品,出自 "深蓝的blog" 博客,欢迎转载.转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog: http://blog.csdn.net/huangyanl ...
- IOS获取来电去电来电归属系统通知达到效果(一)
这里的原理是获得到呼叫系统通知,然后根据本地呼叫电话号码,相应的电话联系. 一世. 来电显示是不是在地址簿中的联系人, 这是当第一个加入一个临时的联系人在您的电话簿(它是创建一个新的接触,并保存相 ...
- TypeError: Cannot read property 'style' of null 错误解决
错误信息例如以下: JSP代码例如以下: <c:if test ="${not empty excelErrors}"> <div id="excelE ...
- SE 2014年5月27日
R1模拟总部,R2 与R3模拟分部 如图配置 要求使用 GRE over IPSec VPN 主模式,启用动态路由协议rip使得总部与两分部内网可相互通讯,但要求分部用户数据流不允许互通! 步骤: 1 ...
- WebGL自学教程——WebGL演示样例:開始
最终開始WebGL的演示样例了,...... 開始 使用WebGL的步骤,非常easy: 1. 获得WebGL的渲染环境(也叫渲染上下文). 2. 发挥你的想象力,利用<WebGL參考手冊> ...
- [Leetcode]-ReverseLinkedList
题目:单链表取反 #include <stdlib.h> #include <stdio.h> typedef struct node *list; typedef struc ...
- HttpClient请求服务器代码优化版
HttpClient请求服务器代码优化版 首先,我在前面的两篇博文中介绍了在 Android中,除了使用java.net包下HttpUrlConnection的API访问HTTP服务之外,我们还可以换 ...
- 怎样使用jlink一键烧录整个flash Hi3518 a c e Hi3515 Hi3512
以jlink烧录3515为例: 1\在jlink安装文件夹"C:\Program Files\SEGGER\JLinkARM_V426b"建立批处理文件"HI3515烧写 ...
- iosclient暑期“动画屋“活动项目总结
入职实习的这个公司,第一天就分配了任务.从零開始写一个网页.之前尽管了解一些前端知识.但从头开写还是遇到了非常多问题,互联网公司讲求效率,有deadline还是比較有紧迫感的,与在实验室放羊状 ...