iphone开发之UITabBarController的使用

查看了自己最新写的文章日期,居然是2012年2月份,2月份到现在我没用文章记录我的成长,也没有与大家共同分享,我表示很失败。因公司需要现在不得不转向ios的开发,我也不得不慢慢的开始摸索着前进,好了废话不多说,切入正题吧。

tb

以上图片中的,常用灯光、灯光控制、场景控制、系统设置这样的功能按钮样式想必大家都不陌生吧!这是一个我开发的一个android项目,其中用到的是我没采用android的Tab控件,写的自定义控件结合ActivityGroup完成的。而在我的另外 一个项目同样需要实现这样的功能,此时UITabBarController帮助了我。大家看到了这样的效果,下面我们一步一步实现它吧!

1、首先我使用xcode创建了一个项目,创建了四个ViewController,分别是FavoriteViewControl、LightingViewController、SceneViewController、SystemSettingViewController,在AppDelegate.h文件中引入四个ViewController的头文件。

2、构建一个NSArray,分别以四个ViewController为元素。

3、在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions在该函数中创建一个UITabBarController,

4、在AppDelegate的头文件中,实现UITabBarControllerDelegate与UITabBarDelegate代理。

5、UITabBarController中viewControllers为一个重要的属性,此时需要将先前定义的NSArray赋给该对象。

具体代码实现如下:

FavoriteViewController *favoriteViewController = [[FavoriteViewController alloc] init];
    favoriteViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    
    LightingViewController *lightingViewController = [[LightingViewController alloc] init];
    lightingViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
    
    SceneViewController *sceneViewController = [[SceneViewController alloc] init];
    sceneViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
    
    SystemSettingViewController *systemSettingViewController = [[SystemSettingViewController alloc] init];
    systemSettingViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:3];
    
    
    NSArray *array = [[NSArray alloc] initWithObjects:favoriteViewController, lightingViewController, sceneViewController, systemSettingViewController, nil];
    
    
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.delegate = self;
    tab.viewControllers = array; //用于指定UITabBarController的View
    tab.selectedIndex = 0;

小弟也是刚接触IOS,在开发项目的过程中积累,如果不懂的共同学习,当然大牛们就请赐教。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值