ios-使用标签导航模式

来源:互联网 发布:安卓处理json实体类 编辑:程序博客网 时间:2024/06/05 19:48

// 标签导航模式

/*

标签导航模式是非常重要的导航模式。使用标签狼时,有一定的指导原则:标签栏位于屏幕下方,占有49点的屏幕空间,有时可以隐藏起来;为了点击方便,标签栏中的标签不能超过5个,超过5个,则最后一个显示为“更多,点击“更多”标签会出现更多的列表”。

*/


代码实现如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];    self.window.backgroundColor = [UIColor grayColor];    [self.window makeKeyAndVisible];        UITabBarController *tabBarViewController = [[UITabBarController alloc] init];    self.window.RootViewController = tabBarViewController;    [tabBarViewController release];        FirstViewController* first = [[FirstViewController alloc]init];    SecondViewController* second = [[SecondViewController alloc]init];    tabBarViewController.viewControllers = [NSArray arrayWithObjects:first, second, nil];    [first release];    [second release];        // 设置UITabBarItem标题    UITabBar *tabBar = tabBarViewController.tabBar;    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];    tabBarItem1.title = @"第一视图";    tabBarItem2.title = @"第二视图";    /*     注意:这里有多少个视图控制器,就有多少个UITabBarItem,不能超过视图控制器的个数,如果过视图控制器超过5个,最后一个将会显示more     */        // 设置UITabBarItem的icon和选中icon    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"111.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"111.png"]];    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"222.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"222.png"]];        // 设置UITabBarItem标题文字选中颜色    UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];    [[UITabBarItem appearance] setTitleTextAttributes:     [NSDictionary dictionaryWithObjectsAndKeys:titleHighlightedColor, UITextAttributeTextColor,                                                       nil] forState:UIControlStateHighlighted];        return YES;}


至此,标签导航介绍已经完毕,程序运行效果图如下:

ios 6效果图:



ios 7效果图:



0 0
原创粉丝点击