ios ios 底部tabbar 怎么让它默认显示某一个item
1个回答
展开全部
iOS发UI篇—UITabBarController简单介绍
、简单介绍
UITabBarControllerUINavigationController类似,UITabBarController轻松管理控制器,轻松完控制器间切换,典型例QQ、微信等应?
二、UITabBarController使用
1.使用步骤:
(1)初始化UITabBarController
(2)设置UIWindowrootViewControllerUITabBarController
(3)创建相应控制器(viewcontroller)
(4)控制器添加UITabBarController
2.代码示例
新建空文件Application代理编码
YYAppDelegate.m文件
1 //
2 // YYAppDelegate.m
3 // 01-UITabBar控制器基本使用
4 //
5 // Created by 孔医 on 14-6-7.
6 // Copyright (c) 2014 itcast. All rights reserved.
7 //
8
9 #import "YYAppDelegate.h"
10
11 @implementation YYAppDelegate
12
13 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
14 {
15 //1.创建Window
16 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
17 self.window.backgroundColor = [UIColor whiteColor];
18
19 //a.初始化tabBar控制器
20 UITabBarController *tb=[[UITabBarController alloc]init];
21 //设置控制器Window根控制器
22 self.window.rootViewController=tb;
23
24 //b.创建控制器
25 UIViewController *c1=[[UIViewController alloc]init];
26 c1.view.backgroundColor=[UIColor grayColor];
27 c1.view.backgroundColor=[UIColor greenColor];
28 c1.tabBarItem.title=@"消息";
29 c1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
30 c1.tabBarItem.badgeValue=@"123";
31
32 UIViewController *c2=[[UIViewController alloc]init];
33 c2.view.backgroundColor=[UIColor brownColor];
34 c2.tabBarItem.title=@"联系";
35 c2.tabBarItem.image=[UIImage imageNamed:@"tab_buddy_nor"];
36
37 UIViewController *c3=[[UIViewController alloc]init];
38 c3.tabBarItem.title=@"态";
39 c3.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];
40
41 UIViewController *c4=[[UIViewController alloc]init];
42 c4.tabBarItem.title=@"设置";
43 c4.tabBarItem.image=[UIImage imageNamed:@"tab_me_nor"];
44
45
46 //c.添加控制器ITabBarController
47 //c.1第种式
48 // [tb addChildViewController:c1];
49 // [tb addChildViewController:c2];
50
51 //c.2第二种式
52 tb.viewControllers=@[c1,c2,c3,c4];
53
54
55 //2.设置Window主窗口并显示
56 [self.window makeKeyAndVisible];
57 return YES;
58 }
59
60 @end
、简单介绍
UITabBarControllerUINavigationController类似,UITabBarController轻松管理控制器,轻松完控制器间切换,典型例QQ、微信等应?
二、UITabBarController使用
1.使用步骤:
(1)初始化UITabBarController
(2)设置UIWindowrootViewControllerUITabBarController
(3)创建相应控制器(viewcontroller)
(4)控制器添加UITabBarController
2.代码示例
新建空文件Application代理编码
YYAppDelegate.m文件
1 //
2 // YYAppDelegate.m
3 // 01-UITabBar控制器基本使用
4 //
5 // Created by 孔医 on 14-6-7.
6 // Copyright (c) 2014 itcast. All rights reserved.
7 //
8
9 #import "YYAppDelegate.h"
10
11 @implementation YYAppDelegate
12
13 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
14 {
15 //1.创建Window
16 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
17 self.window.backgroundColor = [UIColor whiteColor];
18
19 //a.初始化tabBar控制器
20 UITabBarController *tb=[[UITabBarController alloc]init];
21 //设置控制器Window根控制器
22 self.window.rootViewController=tb;
23
24 //b.创建控制器
25 UIViewController *c1=[[UIViewController alloc]init];
26 c1.view.backgroundColor=[UIColor grayColor];
27 c1.view.backgroundColor=[UIColor greenColor];
28 c1.tabBarItem.title=@"消息";
29 c1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
30 c1.tabBarItem.badgeValue=@"123";
31
32 UIViewController *c2=[[UIViewController alloc]init];
33 c2.view.backgroundColor=[UIColor brownColor];
34 c2.tabBarItem.title=@"联系";
35 c2.tabBarItem.image=[UIImage imageNamed:@"tab_buddy_nor"];
36
37 UIViewController *c3=[[UIViewController alloc]init];
38 c3.tabBarItem.title=@"态";
39 c3.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];
40
41 UIViewController *c4=[[UIViewController alloc]init];
42 c4.tabBarItem.title=@"设置";
43 c4.tabBarItem.image=[UIImage imageNamed:@"tab_me_nor"];
44
45
46 //c.添加控制器ITabBarController
47 //c.1第种式
48 // [tb addChildViewController:c1];
49 // [tb addChildViewController:c2];
50
51 //c.2第二种式
52 tb.viewControllers=@[c1,c2,c3,c4];
53
54
55 //2.设置Window主窗口并显示
56 [self.window makeKeyAndVisible];
57 return YES;
58 }
59
60 @end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询