UITabBarController使用
来源:互联网 发布:知乎 横渡太平洋 编辑:程序博客网 时间:2024/06/05 15:25
参考文献:http://blog.csdn.net/lovefqing/article/details/8255846
UITabBarController使用是没什么问题,问题是如何在使用的过程中能正常使用导航视图,正常添加代码是无法实现的,需要自己在每个页面添加一个导航视图UINavigationController;
具体代码如下:
@interface AppDelegate ()
@property (nonatomic,strong)UITabBarController* mainTabBarController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UCFirstViewController* firstView = [[UCFirstViewControlleralloc] init];
UINavigationController* firstNavi = [[UINavigationControlleralloc]initWithRootViewController:firstView];
UCSecondViewController* secondView = [[UCSecondViewControlleralloc] init];
UINavigationController* secondNavi = [[UINavigationControlleralloc]initWithRootViewController:secondView];
UCThreeViewController* threeView = [[UCThreeViewControlleralloc] init];
UINavigationController* threeNavi = [[UINavigationControlleralloc]initWithRootViewController:threeView];
UCFourViewController* fourView = [[UCFourViewControlleralloc] init];
UINavigationController* fourNavi = [[UINavigationControlleralloc]initWithRootViewController:fourView];
UCFiveViewController* fiveView = [[UCFiveViewControlleralloc] init];
UINavigationController* fiveNavi = [[UINavigationControlleralloc]initWithRootViewController:fiveView];
self.mainTabBarController = [[UITabBarControlleralloc]init];
self.mainTabBarController.viewControllers = [[NSArrayalloc]initWithObjects:firstNavi,secondNavi,threeNavi,fourNavi,fiveNavi,nil];
self.mainTabBarController.tabBar.barTintColor = [UIColorblackColor];
//改变标题颜色
[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
[UIColorwhiteColor],NSForegroundColorAttributeName,
nil]forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [[UCToolsharedServer]colorWithHexString:@"ff4500"];
[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
titleHighlightedColor,NSForegroundColorAttributeName,
nil]forState:UIControlStateSelected];
//标签声明
UIImage* firstImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/first"];
UIImage* firstSelectImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/first_pre"];
firstSelectImage = [firstSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* firstItem = [[UITabBarItemalloc]initWithTitle:@"精选"image:firstImageselectedImage:firstSelectImage];
firstNavi.tabBarItem = firstItem;
UIImage* secondImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/second"];
UIImage* secondSelectImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/second_pre"];
secondSelectImage = [firstSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* secondItem = [[UITabBarItemalloc]initWithTitle:@"发现"image:secondImageselectedImage:secondSelectImage];
secondNavi.tabBarItem = secondItem;
UIImage* threeImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/three"];
UIImage* threeSelectImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/three_pre"];
threeSelectImage = [firstSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* threeItem = [[UITabBarItemalloc]initWithTitle:@"发布"image:threeImageselectedImage:threeSelectImage];
threeNavi.tabBarItem = threeItem;
UIImage* fourImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/four"];
UIImage* fourSelectImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/four_pre"];
fourSelectImage = [firstSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* fourItem = [[UITabBarItemalloc]initWithTitle:@"管理"image:fourImageselectedImage:fourSelectImage];
fourNavi.tabBarItem = fourItem;
UIImage* fiveImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/five"];
UIImage* fiveSelectImage = [[UCToolsharedServer]getImageFromTBBundleWithImageName:@"tabbar/five_pre"];
fiveSelectImage = [firstSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* fiveItem = [[UITabBarItemalloc]initWithTitle:@"我的"image:fiveImageselectedImage:fiveSelectImage];
fiveNavi.tabBarItem = fiveItem;
self.window.rootViewController = self.mainTabBarController;
[self.windowmakeKeyAndVisible];
returnYES;
}
实现的效果图如下:
其中关键的代码是:self.window.rootViewController = self.mainTabBarController;
我们习惯的写法是:self.window.rootViewController = [[UINavigationControlleralloc]initWithRootViewController:self.mainTabBarController];
按照习惯的写法就会导致我们无法正常使用自己写的导航视图UINavigationController对象,而会被UITabBarController的导航视图给覆盖
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用 .
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController使用
- UITabBarController的使用总结
- UITabbarController使用汇总
- UITabBarController使用详解
- UITabBarController使用详解
- UITabBarController使用详解
- UITabBarController的使用总结
- Spring 三大基础组件简介
- 【C语言】找出数组中的最大值,最小值,之差
- 百度网盘爬虫(如何爬取百度网盘)
- php 面向对象编程的高级技术
- Xcode绘制图片水印
- UITabBarController使用
- mdev和udev
- C#网络/检测某端口是否被占用的方法
- 51单片机中断学习
- 64位linux中的inet_ntoa问题
- 构建工具-Maven
- jQuery学习笔记(二)选择器
- 常量指针与指针常量的区别
- bzoj 3173: [Tjoi2013]最长上升子序列(splay)