[iOS diary]iOS6样式兼容之 NavigationBar和TabBar 样式扁平化 兼容iOS7样式 全局实现
来源:互联网 发布:java电商架构 编辑:程序博客网 时间:2024/05/01 01:42
一篇跟iOS6 样式扁平化的好文章:http://www.tuicool.com/articles/6NFfYj
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]]; 去掉后背的黑色背景 或 在
[[UITabBar appearance] setTintColor:[UIColor clearColor]];时去掉后上方的粗黑边
[[UITabBar appearance]setShadowImage:[[UIImagealloc]init]];去掉上方的浅阴影。
iOS7兼容iOS6选中图片
UITabBarItem *item = [[UITabBarItemalloc]initWithTitle:@"直播"image:[UIImageimageNamed:@"tab_icon_home_normal"] tag:0];
if([[[UIDevicecurrentDevice]systemVersion]floatValue] >= 7.0)
{
[itemsetSelectedImage:[UIImageimageNamed:@"tab_icon_home_selected"]];
}
else
{
[itemsetFinishedSelectedImage:[UIImageimageNamed:@"tab_icon_home_selected"]withFinishedUnselectedImage:[UIImageimageNamed:@"tab_icon_home_normal"]];
}
以下为对iOS6 NavigationBar与TabBar 样式扁平化的代码。
1、对UINavigationBar 与 UITabBar的全局样式修改,写在AppDelegate LaunchFinish中
- (void)setupUIAppearance{[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:81.0/255 green:196.0/255 blue:212.0/255 alpha:1]];[[UITabBarItem appearance] setTitleTextAttributes: @{ UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextColor: [UIColor lightGrayColor] } forState:UIControlStateSelected];[[UITabBarItem appearance] setTitleTextAttributes: @{ UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextColor: [UIColor lightGrayColor] } forState:UIControlStateNormal];UIColor *navigationBarColor = [UIColor colorWithRed:81.0/255 green:196.0/255 blue:212.0/255 alpha:1];if(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];[[UITabBar appearance] setSelectedImageTintColor:[UIColor clearColor]];[[UINavigationBar appearance] setTintColor:navigationBarColor];[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];[[UIBarButtonItem appearance] setBackgroundImage:[UIImage new]forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];[[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:navigationBarColor size:CGSizeMake(1, 44)] forBarMetrics:UIBarMetricsDefault];[[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName: [UIFont boldSystemFontOfSize:20],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero]}];[[UIBarButtonItem appearance] setTitleTextAttributes: @{ UITextAttributeFont: [UIFont systemFontOfSize:17], UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero]} forState:UIControlStateNormal];[[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(1, 49)]];[[UITabBar appearance] setSelectionIndicatorImage:[UIImage new]];}else{[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:81.0/255 green:196.0/255 blue:212.0/255 alpha:1]];}}
2、TabBar图片设置如下
- (void)setupTabBarItemsAndViewControllers{NSMutableArray *mutableTabBarItems = [NSMutableArray array];NSMutableArray *mutableViewControllers = [NSMutableArray array];CCMoreOptionsViewController *moreOptionsViewController = [[CCMoreOptionsViewController alloc] initWithNibName:nil bundle:nil];for(NSInteger i = 0; i < CC_TAB_BAR_ITEM_TYPE_TOTAL_NUMBER ; i++){switch (i) {case CCTabBarItemTypeLiveShow:{UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"xxxx" image:[UIImage imageNamed:@"tab_icon_home_normal"] tag:0];if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){[item setSelectedImage:[UIImage imageNamed:@"tab_icon_home_selected"]];}else{[item setFinishedSelectedImage:[UIImage imageNamed:@"tab_icon_home_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_icon_home_normal"]];}[mutableTabBarItems addObject:item];UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:moreOptionsViewController];vc.tabBarItem = item;[mutableViewControllers addObject:vc];break;}case CCTabBarItemTypeMessage:{UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"消息" image:[UIImage imageNamed:@"tab_icon_message_normal"] tag:1];if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){[item setSelectedImage:[UIImage imageNamed:@"tab_icon_message_selected"]];}else{[item setFinishedSelectedImage:[UIImage imageNamed:@"tab_icon_message_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_icon_message_normal"]];}[mutableTabBarItems addObject:item];UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:moreOptionsViewController];vc.tabBarItem = item;[mutableViewControllers addObject:vc];break;}case CCTabBarItemTypeMobileGameVideo:{UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"xxxx" image:[UIImage imageNamed:@"tab_icon_video_normal"] tag:1];if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){[item setSelectedImage:[UIImage imageNamed:@"tab_icon_video_selected"]];}else{[item setFinishedSelectedImage:[UIImage imageNamed:@"tab_icon_video_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_icon_video_normal"]];}[mutableTabBarItems addObject:item];UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:moreOptionsViewController];vc.tabBarItem = item;[mutableViewControllers addObject:vc];break;}case CCTabBarItemTypeMoreOptions:{UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"更多" image:[UIImage imageNamed:@"tab_icon_more_normal"] tag:1];if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){[item setSelectedImage:[UIImage imageNamed:@"tab_icon_more_selected"]];}else{[item setFinishedSelectedImage:[UIImage imageNamed:@"tab_icon_more_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_icon_more_normal"]];}[mutableTabBarItems addObject:item];UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:moreOptionsViewController];vc.tabBarItem = item;[mutableViewControllers addObject:vc];break;}default:break;}}self.viewControllers = mutableViewControllers;}
3、设置NavigationBar如下
- (void)setupNavigationBar{BOOL isLogin = YES;if(isLogin){CGRect rect = CGRectMake(0, 0, 30, 30);UIButton *headPhotoButton = [[UIButton alloc] initWithFrame:rect];[headPhotoButton setImage:[UIImage imageNamed:@"icon_default_avatar"] forState:UIControlStateNormal];UIButton *historyButton = [[UIButton alloc] initWithFrame:rect];[historyButton setImage:[UIImage imageNamed:@"nav_icon_history_normal"] forState:UIControlStateNormal];UIButton *searchButton = [[UIButton alloc] initWithFrame:rect];[searchButton setImage:[UIImage imageNamed:@"nav_icon_search_normal"] forState:UIControlStateNormal];[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:headPhotoButton]];[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithCustomView:historyButton],[[UIBarButtonItem alloc] initWithCustomView:searchButton], nil]];}else{}}
结果图如下
、
- [iOS diary]iOS6样式兼容之 NavigationBar和TabBar 样式扁平化 兼容iOS7样式 全局实现
- ios-设置navigationBar和tabBar的样式
- 兼容IOS7和IOS6
- iOS 设置NavigationBar和BarButtonItem的主题样式(iOS 6和iOS7适配)
- 兼容IE8样式
- div+css样式兼容
- css样式+属性兼容
- 样式兼容IE7
- select兼容ie6样式
- textarea、input样式兼容
- CSS样式常用兼容属性之日积月累
- 【iOS开发技术】将iOS6 原生Navigtaion和Tab 修改的接近iOS7的样式
- iOS 使用 Interface Builder 兼容 iOS6 和iOS7
- iOS兼容开发:让程序同时支持iOS6和iOS7
- iOS6兼容iOS7界面(界面上移,navigationbar 颜色)
- iOS 设置NavigationBar的样式
- ios--ios6与ios7界面兼容(解决方案)
- ios--ios6与ios7界面兼容(解决方案)
- linux上安装库注意事项
- Trie树学习
- 分割问题小结
- android API 积累之 可以判断是否是view 是否是 Imageview 的实例
- [toj4087]m个不同的箱子放n种不同的球
- [iOS diary]iOS6样式兼容之 NavigationBar和TabBar 样式扁平化 兼容iOS7样式 全局实现
- CppCMS 1.0.4 发布,高性能 C++ 的Web框架
- POJ 1258 Agri-Net 最小生成树 Prim算法
- 中国象棋之将帅问题
- 有时候,html转义会让你头疼
- 用ElasticSearch和mongodb River搭建一个简单地search工程。
- C语言中的无符号数和有符号数
- GIT 2.0.4服务器搭建以及如何使用
- IOS之同步请求、异步请求、GET请求、POST请求