您的位置:首页 > 产品设计 > UI/UE

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返回的时候重新出现的效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: