UITabBarController

1.组成

最下层是:tabbar 中间是:custom content  最上面:Tab bar controller view

Tab Bar上面显示的每一个Tab都对应着一个View Controller.

ViewController本身具有一个tabBarItem属性,只要设置它,就能改变Tab Bar上对应的显示内容。

如果不主动设置,系统将会根据viewController的标题自动创建一个,该tabBarItem中会显示文字,没有图像。自己创建UITabBarItem,可以指定显示的图像和对应的文字。

UITabBarItem还有一个badgeValue,该属性可以在其右下角显示一个小的角标,通常用于提示用户有新的消息。

2.使用方式

加载方式

a.application delegate中的applicationDidFinishLanunching:方法中创建和加载,因为UITabBarController通常作为整个程序的rootViewController

b.与UINavigationController结合,如IPhone的音乐和App Store

 

 1 #import "AppDelegate.h"
 2 #import "FirstViewController.h"
 3 #import "SecondViewController.h"
 4 #import "ThridViewController.h"
 5 
 6 @interface AppDelegate ()
 7 
 8 @property (retain,nonatomic) UITabBarController *tarBar;
 9 @end
10 
11 @implementation AppDelegate
12 
13 
14 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
15     // Override point for customization after application launch.
16     
17     self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
18     self.window.backgroundColor=[UIColor whiteColor];
19     [self.window makeKeyAndVisible];
20     
21     self.tarBar=[[UITabBarController alloc]init];
22     
23     FirstViewController *f=[[FirstViewController alloc]init];
24     SecondViewController *s=[[SecondViewController alloc]init];
25     ThridViewController *t=[[ThridViewController alloc]init];
26  
27     f.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"第一个" image:[UIImage imageNamed:@"calendar.png"] tag:0];
28     s.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"第二个" image:[UIImage imageNamed:@"datashow.png"] tag:1];
29     t.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"第三个" image:[UIImage imageNamed:@"number.png"] tag:2];
30    // f.tabBarItem.badgeValue=@"99+";
31     s.tabBarItem.badgeValue=@"中文";
32     self.tarBar.viewControllers=[NSArray arrayWithObjects:f,s,t, nil];
33     self.window.rootViewController=self.tarBar;
34     
35     return YES;
36 }
View Code

 

posted @ 2015-08-03 16:29  一只简单的码农  阅读(132)  评论(0编辑  收藏  举报