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

系统UITabbarController

2016-02-18 11:43 411 查看
新建MainTabbarController类

在MainTabbarController.m中

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//创建viewContronllers
[self createViewControllers];
//创建tabBarItems
[self createItems];
}

#pragma mark 创建viewControllers

- (void)createViewControllers
{
UINavigationController * nc1 = [[UINavigationController alloc] initWithRootViewController:[[viewController1 alloc] init]];
UINavigationController * nc2 = [[UINavigationController alloc] initWithRootViewController:[[viewController2 alloc] init]];
UINavigationController * nc3 = [[UINavigationController alloc] initWithRootViewController:[[viewController3 alloc] init]];

self.viewControllers = @[nc1,nc2,nc3];
}

- (void)createItems
{
NSArray *titleArray = @[@"1", @"2", @"3"];
NSArray *selectImageName = @[@"selected1.png", @"selected2.png", @"selected3.png"];
NSArray *unselectImageName = @[@"normal1.png", @"normal2.png", @"normal3.png"];
for (int i = 0; i < titleArray.count; i++) {
//需要对图片进行单独处理
UIImage *selectImage = [UIImage imageNamed:selectImageName[i]];
selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *unselectImage = [UIImage imageNamed:unselectImageName[i]];
unselectImage = [unselectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//以上是防止在bar上显示为阴影而不是图片
UITabBarItem *item = self.tabBar.items[i];
item.selectedImage = selectImage;
item.image = unselectImage;
item.title = titleArray[i];
}
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"img_tabBar_bg_iOS8.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor darkGrayColor]} forState:UIControlStateNormal];
}


特别鸣谢 詹Q同学
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: