TabBar的使用,一个应用程序中,tablebar始终存在于界面下方

本文介绍如何在iOS应用中实现类似满座APP的TabBar功能。通过在AppDelegate中设置TabBarController,添加对应的ViewController,并配置每个TabBarItem的标题和图片,创建NavigationController来实现各个页面的导航。代码示例详细展示了整个过程,适合iOS初学者参考。

如果你想做一个类似于满座的下面的tablebar下面的功能,

那么恭喜你找对了,直接上代码

首先在AppDelegate.h里面添加以下代码

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarDelegate,UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@property(nonatomic,retain)UITabBarController*tabBarController;

@end

然后在AppDelegate.m

导入所创建类的头文件

然后在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    

    _tabBarController=[[UITabBarController alloc]init];

    _tabBarController.delegate=self;


    MainViewController*first=[[MainViewController alloc]init];

    first.tabBarItem.title=@"主页";

    first.tabBarItem.image=[UIImage imageNamed:@"a.png"];


    NearViewController *second=[[NearViewController alloc]init];

    second.tabBarItem.title=@"周边";

    second.tabBarItem.image=[UIImage imageNamed:@"c.png"];

    

    SearchViewController*third=[[SearchViewController alloc]init];

    third.tabBarItem.title=@"搜索";

    third.tabBarItem.image=[UIImage imageNamed:@"e.png"];

   

    AppSetingViewController*fourth=[[AppSetingViewController alloc]init];

    fourth.tabBarItem.title=@"满座";

    fourth.tabBarItem.image=[UIImage imageNamed:@"s.png"];

    

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

    UINavigationController * nav2 =[[UINavigationController alloc]initWithRootViewController:second];

    UINavigationController * nav3 =[[UINavigationController alloc]initWithRootViewController:third];

    UINavigationController * nav4 =[[UINavigationController alloc]initWithRootViewController:fourth];

    NSArray * nsa =[[NSArray alloc]initWithObjects:nav1,nav2,nav3,nav4, nil];

    _tabBarController.viewControllers=nsa;

    self.window.rootViewController=_tabBarController;

    

    [first release];

    [second release];

    [third release];

    [fourth release];

    [nav1 release];

    [nav2 release];

    [nav3 release];

    [nav4 release];

    [nsa release];

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

   

}

添加以下的代码,就可以实现上述功能了,小弟是ios初学者,可能有些地方描述不准确,代码书写不规范,希望各位大牛勿喷,同时希望给予指导和帮助。

写这篇博客就是自己的一个随身笔记,希望对各位有所帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值