(原) 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)
2012-03-21 23:35
441 查看
(注: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
相关文章推荐
- 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)/IOS5&IOS4
- 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换...
- iOS开发制造一个UITabBarController标签控制器、定制UITabBarItem文字图片的6种方式以及More
- ios更改UITabBarController背景以及选中背景图片的方法 以及隐藏tabbar
- 【iOS开发-28】制造一个UITabBarController标签控制器、定制UITabBarItem文字图片的6种方式以及More讲解
- UITabBarController 之 设置选中和未选中的图片 隐藏tabbar
- UITabBarController TabBarItem 点击事件
- UINavigationController、UITabBarController 支持屏幕自动旋转问题
- 【iOS发展-28】制造业UITabBarController标记控制器、定制UITabBarItem文字图像6途径和More评论
- UITabBarController 之 设置选中和未选中的图片 隐藏tabbar
- Swift修改tabBarItem选中色和tabBar背景色
- NavigationController与TabBarController同时存在时self.tabBarItem.title = @"xxx"设置失效以及‘ selectedImage’
- ios更改UITabBarController背景以及选中背景图片的方法
- uitabbarcontroller上的tabbaritem的图片设置
- ios更改UITabBarController背景以及选中背景图片的方法
- ios6.0 UINavigationController、UITabBarController 支持屏幕自动旋转问题
- 从一个控制器返回后,控制器所属的tabbarController没选中(tabbarItem图标不亮)
- iOS开发- UITabBarController的TabBar、TabBarItem背景颜色设置
- iOS自定制tabbar与系统的tabbar冲突,造成第一次点击各个item图片更换选中,第二次选中部分item图片不改变
- 给系统的UITabbarViewController 的tabBarItem 添加图片的问题