UITabBarController自定义以及隐藏
2014-11-11 17:26
381 查看
首先
#import <UIKit/UIKit.h>
@interface CustomTabBar :
UITabBarController
@end
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
[selfcreateController];
}
-(void)createController{
//创建三个控制器
DiscloseViewController * disVC = [[DiscloseViewControlleralloc]init];
UINavigationController * disNav = [[UINavigationControlleralloc]initWithRootViewController:disVC];
AnswerViewController * anVC = [[AnswerViewControlleralloc]init];
UINavigationController * anNav = [[UINavigationControlleralloc]initWithRootViewController:anVC];
MyViewController * myVC = [[MyViewControlleralloc]init];
UINavigationController * myNav = [[UINavigationControlleralloc]initWithRootViewController:myVC];
self.viewControllers =@[disNav,anNav,myNav];
UITabBar * tabbar = self.tabBar;
UITabBarItem * tabbaritem1 = [tabbar.itemsobjectAtIndex:0];
UITabBarItem * tabbaritem2 = [tabbar.itemsobjectAtIndex:1];
UITabBarItem * tabbaritem3 = [tabbar.itemsobjectAtIndex:2];
//标题
NSArray * titleArr = @[@"爆料",@"抢答",@"我的"];
tabbaritem1.title = titleArr[0];
tabbaritem2.title = titleArr[1];
tabbaritem3.title = titleArr[2];
//图片
//背景图案
// [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"mid_bg_press"]];
//字体颜色
NSArray * UnSelectImg=@[@"icon1_normal.png",@"icon3_normal.png",@"icon4_normal.png"];
NSArray * SelectImg=@[@"icon1_press.png",@"icon3_press.png",@"icon4_press.png"];
for (int i =
0 ; i < self.tabBar.items.count; i++) {
UITabBarItem * Item =[self.tabBar.itemsobjectAtIndex:i];
// [Item setFinishedSelectedImage:[UIImage imageNamed:SelectImg[i]] withFinishedUnselectedImage:[UIImage imageNamed:UnSelectImg[i]]];//IOS7之前用
UIImage * image = [UIImageimageNamed:UnSelectImg[i]];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Item.image = image;
image = [UIImage imageNamed:SelectImg[i]];
[Item setImageInsets:UIEdgeInsetsMake(5,0, -5,0)];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Item.selectedImage = image;
Item.title=titleArr[i];
[[UITabBarItemappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:
[UIColorcolorWithRed:22/256.0fgreen:177/256.0fblue:255/256.0falpha:1]}forState:UIControlStateHighlighted];//字体颜色
}
self.selectedIndex =1;//选中的显示控制器
}
有的页面需要隐藏返回的时候重新显示可以采用下面方法
ChatViewController * chatController = [[ChatViewControlleralloc]
initWithChatter:@"182"isGroup:NO];
chatController.title =
@"182";
chatController.hidesBottomBarWhenPushed =YES;//隐藏
[self.navigationControllerpushViewController:chatController
animated:YES];
chatController.hidesBottomBarWhenPushed =NO;//显示
这样就可以达到推出页面没有TabBar返回的时候重新出现的效果
#import <UIKit/UIKit.h>
@interface CustomTabBar :
UITabBarController
@end
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
[selfcreateController];
}
-(void)createController{
//创建三个控制器
DiscloseViewController * disVC = [[DiscloseViewControlleralloc]init];
UINavigationController * disNav = [[UINavigationControlleralloc]initWithRootViewController:disVC];
AnswerViewController * anVC = [[AnswerViewControlleralloc]init];
UINavigationController * anNav = [[UINavigationControlleralloc]initWithRootViewController:anVC];
MyViewController * myVC = [[MyViewControlleralloc]init];
UINavigationController * myNav = [[UINavigationControlleralloc]initWithRootViewController:myVC];
self.viewControllers =@[disNav,anNav,myNav];
UITabBar * tabbar = self.tabBar;
UITabBarItem * tabbaritem1 = [tabbar.itemsobjectAtIndex:0];
UITabBarItem * tabbaritem2 = [tabbar.itemsobjectAtIndex:1];
UITabBarItem * tabbaritem3 = [tabbar.itemsobjectAtIndex:2];
//标题
NSArray * titleArr = @[@"爆料",@"抢答",@"我的"];
tabbaritem1.title = titleArr[0];
tabbaritem2.title = titleArr[1];
tabbaritem3.title = titleArr[2];
//图片
//背景图案
// [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"mid_bg_press"]];
//字体颜色
NSArray * UnSelectImg=@[@"icon1_normal.png",@"icon3_normal.png",@"icon4_normal.png"];
NSArray * SelectImg=@[@"icon1_press.png",@"icon3_press.png",@"icon4_press.png"];
for (int i =
0 ; i < self.tabBar.items.count; i++) {
UITabBarItem * Item =[self.tabBar.itemsobjectAtIndex:i];
// [Item setFinishedSelectedImage:[UIImage imageNamed:SelectImg[i]] withFinishedUnselectedImage:[UIImage imageNamed:UnSelectImg[i]]];//IOS7之前用
UIImage * image = [UIImageimageNamed:UnSelectImg[i]];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Item.image = image;
image = [UIImage imageNamed:SelectImg[i]];
[Item setImageInsets:UIEdgeInsetsMake(5,0, -5,0)];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Item.selectedImage = image;
Item.title=titleArr[i];
[[UITabBarItemappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:
[UIColorcolorWithRed:22/256.0fgreen:177/256.0fblue:255/256.0falpha:1]}forState:UIControlStateHighlighted];//字体颜色
}
self.selectedIndex =1;//选中的显示控制器
}
有的页面需要隐藏返回的时候重新显示可以采用下面方法
ChatViewController * chatController = [[ChatViewControlleralloc]
initWithChatter:@"182"isGroup:NO];
chatController.title =
@"182";
chatController.hidesBottomBarWhenPushed =YES;//隐藏
[self.navigationControllerpushViewController:chatController
animated:YES];
chatController.hidesBottomBarWhenPushed =NO;//显示
这样就可以达到推出页面没有TabBar返回的时候重新出现的效果
相关文章推荐
- iOS 隐藏tabBar UITabBarController 以及 于UINavigationController 配合使用 push
- IOS研究之UITabBarController隐藏tabBar以及addChildViewController
- iOS 自定义UITabBarController以及UITabBar的分析
- ios更改UITabBarController背景以及选中背景图片的方法 以及隐藏tabbar
- 本文对UITabBarController进行分析,研究苹果内部是怎么构造出这个类的,以及我们怎么去自定义一个类
- 自定义UITabBarController以及UITabBar的分析
- 自定义UITabBarController以及UITabBar的分析
- 隐藏UINavigationController和UITabBarController
- 在uitabbarviewcontroller的子视图间相互访问,以及在uitabbarviewcontroller中访问其子视图
- 变相隐藏UITabBarController的TabBar
- 自定义UITabBarController的简单例子
- ios更改UITabBarController背景以及选中背景图片的方法
- 问题解决:自动隐藏UITabBar上面的自定义按钮
- UITabBarController 隐藏 Bootom Tab Bar
- (原) 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)
- 自定义UITabbarController
- 系统UITabBarController的tabBar隐藏时显示白条的解决方法
- 自定义UITabBarController简单方法
- UITabBarController 之 设置选中和未选中的图片 隐藏tabbar
- 关于ios中UIBarButtonItem 自定义 ,UITabBarControll 的隐藏