<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;

}


版权声明:本文博主原创文章。博客,未经同意不得转载。

最新文章

  1. C#回顾 –6.特性
  2. 《java集合概述》
  3. 关于easyui遇到的问题
  4. MySQL 服务无法启动。 服务没有报告任何错误。 请键入 NET HELPMSG 3534 以获得更多的帮助。
  5. 17 网络客户端编程 - 《Python 核心编程》
  6. 如何在KVM中管理存储池
  7. Linux基本命令(4)有关关机和查看系统信息的命令
  8. 总结与学习DIV+CSS网页布局技巧
  9. 最近看了点C++,分享一下我的进度吧!
  10. WTL--SDI框架分析
  11. vs中 VMDebugger未能加载导致异常
  12. java基础(十七)----- 浅谈Java中的深拷贝和浅拷贝 —— 面试必问
  13. SQL 无法连接服务器
  14. Java HashMap的死循环 以及 LRUCache的正确实现
  15. springmvc+mybatis+redis的session共享+maven管理
  16. PCB规则设置
  17. 深入浅出MFC——消息映射与命令传递(六)
  18. gulp处理错误
  19. [转]Fragment跳转至Activity或者Fragment
  20. cocos2d-x 环境搭建

热门文章

  1. 11gR2RAC环境DBCA创建一个数据库错误ORA-15055 ORA-15001
  2. Linux共享wifi给Android手机
  3. 【WinRT】【译】【加工】在 XAML 中制作圆形图片
  4. ACdream 1114(莫比乌斯反演)
  5. 自编Ps教程—我的ps图片赞赏
  6. android-包签名
  7. asp.net出现正在中止线程解决方案
  8. hdu2955(变形01背包)
  9. android中更改spinner、AutoCompleteTextView切割线的颜色
  10. 深入java并发Lock一