ios基于UITabBarController实现tab页面切换
来源:互联网 发布:网络电视直播软件下载 编辑:程序博客网 时间:2024/06/05 03:32
首先,带大家来看看实现的效果图,点击底部三个tab按钮来实现页面的切换
具体实现代码如下:
AppDelegate.m
#import "AppDelegate.h"#import "RedViewController.h"#import "GreenViewController.h"#import "BlueViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; self.window.backgroundColor = [UIColor whiteColor]; //创建tabbar所管理的子控制器,每个子控制器都带有一个导航 RedViewController *redVC = [[RedViewController alloc]initWithNibName:@"RedViewController" bundle:nil]; UINavigationController *navi1 = [[UINavigationController alloc]initWithRootViewController:redVC]; GreenViewController *greenVC = [[GreenViewController alloc]initWithNibName:@"GreenViewController" bundle:nil]; UINavigationController *navi2 = [[UINavigationController alloc]initWithRootViewController:greenVC]; BlueViewController *blueVC = [[BlueViewController alloc]initWithNibName:@"BlueViewController" bundle:nil]; UINavigationController *navi3 = [[UINavigationController alloc]initWithRootViewController:blueVC]; //创建UITabBarController对象 UITabBarController *tabbar = [[UITabBarController alloc]init]; //设置tabbar的子控制器 tabbar.viewControllers = @[navi1, navi2, navi3]; //将标签控制器设置为根视图控制器,程序的第一个界面默认为标签控制器所管理的第一个子控制器的视图 self.window.rootViewController = tabbar; [self.window makeKeyAndVisible]; // Override point for customization after application launch. return YES;}- (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end
RedViewController.m
#import "RedViewController.h"@interface RedViewController ()@end@implementation RedViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"红色"; self.tabBarItem.title = @"首页"; self.tabBarItem.image = [UIImage imageNamed:@"menu_a"]; self.tabBarItem.selectedImage = [UIImage imageNamed:@"menu_a1"]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}@end
GreenViewController.m
#import "GreenViewController.h"@interface GreenViewController ()@end@implementation GreenViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"绿色"; self.tabBarItem.title = @"发现"; self.tabBarItem.image = [UIImage imageNamed:@"menu_b"]; self.tabBarItem.selectedImage = [UIImage imageNamed:@"menu_b1"]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}@end
BlueViewController.m
#import "BlueViewController.h"@interface BlueViewController ()@end@implementation BlueViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"蓝色"; self.tabBarItem.title = @"我的"; self.tabBarItem.image = [UIImage imageNamed:@"menu_d"]; self.tabBarItem.selectedImage = [UIImage imageNamed:@"menu_d1"]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}@end
0 0
- ios基于UITabBarController实现tab页面切换
- UITabBarController实现Tab切换
- 基于代码的 UITabbarController与UINavgationController 实现下导航页面切换
- 左侧Tab切换页面实现
- html实现tab页面切换
- Unity3D实现Tab切换,页面切换功能
- UITabBarController 页面切换动画
- ios UITabBarController 切换动画
- 基于Storyboard的 UITabbarController与UINavgationController 实现下导航切换
- 基于RN实现顶部tab导航切换
- 【IOS学习】视图切换,纯代码实现 UITabBarController,NavigationController
- iphone ios UITabBarController 切换动画
- iphone ios UITabBarController 切换动画
- tab切换页面备份
- tab页面切换
- tab页面切换效果
- tab 页面切换
- ios导航实现页面切换
- Handler Messege 使用简单实例-周期性改变字体色
- 关于解决sql server不能以127.0.0.1登录服务器问题的解决
- c++ 析构函数为什么要加virtual
- 总结出来的软件销售问答技巧
- 排序函数中的函数参数cmp
- ios基于UITabBarController实现tab页面切换
- android网络请求 json传输
- Linux下面网卡配置文件,各部分名称英汉对照
- 输出一个整数的每一位
- java(优化15) 报错"java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher"解决方案
- iOS 提交审核之IDFA的介绍
- 使用AFN多张图片上传
- 如何识别图像边缘?
- CalendarView(日历视图)