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

UI_UItabBarController

2015-10-08 10:55 316 查看


AppDelegate.m
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate

- (void)dealloc
{
[_window release];
[super dealloc];
}

// 实时监控选择的tabbar的索引.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"%ld", tabBarController.selectedIndex);

viewController.tabBarItem.badgeValue = nil;
viewController.tabBarItem.badgeValue = @"";
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];

1.创建第一个tabbar.
FirstViewController *first = [[FirstViewController alloc] init];

UINavigationController *firsthNC = [[UINavigationController alloc] initWithRootViewController:first];

// 设定tabbarItem的内容.
firsthNC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1000] autorelease];

2.创建第二个tabbar.
SecondViewController *second = [[SecondViewController alloc] init];
UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:second];
secondNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"1"] selectedImage:[UIImage imageNamed:@"3"]]autorelease];
secondNC.tabBarItem.badgeValue = @"+1";

3.创建第三个tabbar.
ThirdViewController *third = [[ThirdViewController alloc] init];
UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:third];
thirdNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"分享" image:[UIImage imageNamed:@"2"] tag:1001] autorelease];
thirdNC.tabBarItem.badgeValue = @"+99";

4.创建第四个tabbar.
FourthViewController *fourth = [[FourthViewController alloc] init];
UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourth];
fourthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1002];

5.创建第五个tabbar.
FifthViewController *fifth = [[FifthViewController alloc] init];
UINavigationController *fifthNC = [[UINavigationController alloc] initWithRootViewController:fifth];
fifthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1003];

6.创建第六个tabbar.
SixthViewController *sixth = [[SixthViewController alloc] init];
UINavigationController *sixthNC = [[UINavigationController alloc] initWithRootViewController:sixth];
sixthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1004];

7.需要将这些tabBarController加入到数组中
// 设置数组.
UITabBarController *tab = [[UITabBarController alloc] init];
tab.viewControllers = @[firsthNC, secondNC, thirdNC, fourthNC, fifthNC,sixthNC];
self.window.rootViewController = tab;

// 设置外观tabbar
tab.tabBar.translucent = NO;

// 背景颜色.
tab.tabBar.barTintColor = [UIColor magentaColor];
// 选中后的颜色.
tab.tabBar.tintColor = [UIColor blackColor];
// 默认起始页.
tab.selectedIndex = 2;

tab.delegate = self;

[first release];
[firsthNC release];
[tab release];
[second release];
[secondNC release];
[third release];
[thirdNC release];
[fourth release];
[fourthNC release];
[fifth release];
[fifthNC release];
[sixth release];
[sixthNC release];
return YES;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: