定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)/IOS5&IOS4
来源:互联网 发布:网络电视直播大全 编辑:程序博客网 时间:2024/05/18 22:15
(注:IOS5有新的API可以实现这些功能,这里这样搞是为了支持IOS4.)
/* * @brief 定制的tabbar. */#import <UIKit/UIKit.h>@interface XUTabBarController : UITabBarController{@private UIView * bgView4TabBar_;}@end
#import "XUTabBarController.h"@interface XUTabBarController()@property(nonatomic, retain) UIView * bgView4TabBar;- (void)customTabBarBackgroundColor;- (void)setNoHighlightTabBar;@end@implementation XUTabBarController@synthesize bgView4TabBar = bgView4TabBar_;- (void)dealloc{ [bgView4TabBar_ release]; [super dealloc];}- (void)viewDidLoad{ [super viewDidLoad]; [self customTabBarBackgroundColor];}- (void)viewDidUnload{ [super viewDidUnload]; self.bgView4TabBar = nil;}#pragma mark - For iPad Rotate- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if(UIU_IsIPad) { CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; CGRect frame = self.tabBar.frame; frame.origin.x = 0; frame.origin.y = 0; frame.size.width = (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) ? /*横屏*/ appFrame.size.height + 20 : appFrame.size.width + 20; self.bgView4TabBar.frame = frame; }}- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];}#pragma mark - NoHighlightTab- (void)setSelectedIndex:(NSUInteger)index{ [super setSelectedIndex:index]; [self setNoHighlightTabBar];}- (void)setSelectedViewController:(UIViewController *)selectedViewController{ [super setSelectedViewController:selectedViewController]; [self setNoHighlightTabBar];}- (void)setNoHighlightTabBar{ int tabCount = [self.viewControllers count] > 5 ? 5 : [self.viewControllers count]; NSArray * tabBarSubviews = [self.tabBar subviews]; for(int i = [tabBarSubviews count] - 1; i > [tabBarSubviews count] - tabCount - 1; i--) { for(UIView * v in [[tabBarSubviews objectAtIndex:i] subviews]) { if(v && [NSStringFromClass([v class]) isEqualToString:@"UITabBarSelectionIndicatorView"]) {//the v is the highlight view. [v removeFromSuperview]; break; } } }}#pragma mark - Custom TabBar Background Color- (void)customTabBarBackgroundColor{ ///给tabbar换背景色 // //frame CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; CGRect frame = self.tabBar.frame; frame.origin.x = 0; frame.origin.y = 0; frame.size.width = (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? /*横屏*/ appFrame.size.height + 20 : appFrame.size.width + 20; //bg color. #define useTintColor 1 #if useTintColor self.bgView4TabBar = [[[UINavigationBar alloc] initWithFrame:frame] autorelease]; ((UINavigationBar *)self.bgView4TabBar).tintColor = XX_TabBgColor; #else self.bgView4TabBar = [[[UIView alloc] initWithFrame:frame] autorelease]; self.bgView4TabBar.backgroundColor = XX_TabBgColor; #endif //add to. [self.tabBar insertSubview:self.bgView4TabBar atIndex: self.tabBar.subviews.count - (self.viewControllers.count > 5 ? 5 : self.viewControllers.count) ];}@end
转贴:http://www.cnblogs.com/xiaouisme/archive/2012/03/21/2410820.html
- 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)/IOS5&IOS4
- Swift修改tabBarItem选中色和tabBar背景色
- Swift修改tabBarItem选中色和tabBar背景色
- 点击tabbarItem变Item的背景色
- java实现图片的旋转顺带跟换背景色
- ios:UITabBarController 修改背景图,修改选中时背景色
- IOS6.1中,隐藏掉系统tabbar被选中的背景色
- cell选中的背景色
- tabBarItem设置背景色,标题
- ios更改UITabBarController背景以及选中背景图片的方法 以及隐藏tabbar
- 修改系统tabbar的背景色
- TabBar背景色
- listbox选中元素的背景色
- 设置tableview选中行的背景色
- 更改TabLayout选中的背景色
- QScrollBar定制背景色
- tabBar中tabBarItem选中颜色自定义设置
- Sublime Text 3安装以及修改选中背景色
- how to see the num of cpus on ubuntu
- jquery easyui DataGrid 数据表格 属性
- vc++系统托盘
- 如何动态添加菜单/菜单项、子菜单、右键菜单
- GTALK的运行参数
- 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)/IOS5&IOS4
- Request对象
- [Web前端]CSS实现“不可选择,不可复制”面临的问题
- 临终的悲剧——————抢救最后一口气
- 简单的斐波那契数列程序
- WPF 入门
- Darwin在转发流过程中对推送端断开的处理问题
- Ubuntu 12.04 LTS下环境变量设置
- 心得6--XML编程(CRUD)--DOM4J精讲