UI12_UItabBarViewController
2015-10-05 09:06
429 查看
隐藏标签栏:
在ViewWillAppear中写:
AppDelegate.h
AppDelegate.m
firstViewController.h
firstViewController.m
testViewcontroller.h
testViewcontroller.m
SecondViewController ~~~sixthViewController, 依次
在ViewWillAppear中写:
self.tabBarController.tabBar.hidden
AppDelegate.h
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
AppDelegate.m
#import "AppDelegate.h" #import "firstViewController.h" #import "secondViewController.h" #import "thirdViewController.h" #import "fourthViewController.h" #import "fifthViewController.h" #import "sixthViewController.h" @interface AppDelegate ()<UITabBarControllerDelegate> @end @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; [_window release]; firstViewController *firstVC = [[firstViewController alloc] init]; UINavigationController *firstnaVC = [[UINavigationController alloc] initWithRootViewController:firstVC]; // 设定tabbarItem的内容 firstnaVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1000] autorelease]; firstnaVC.tabBarItem.badgeValue = @"+1"; secondViewController *secVC = [[secondViewController alloc] init]; UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC]; secNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"1" ] selectedImage:[UIImage imageNamed:@"2"]] autorelease]; secNAVC.tabBarItem.badgeValue = @"+2"; thirdViewController *thirdVC = [[thirdViewController alloc] init]; UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC]; thirdNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"分享" image:[UIImage imageNamed:@"3"] tag:1001] autorelease]; thirdNAVC.tabBarItem.badgeValue = @"+99"; fourthViewController *fourVC = [[fourthViewController alloc] init]; UINavigationController *fourNAVC = [[UINavigationController alloc] initWithRootViewController:fourVC]; fourNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1002] autorelease]; fourNAVC.tabBarItem.badgeValue = @"+4"; fifthViewController *fifthVC = [[fifthViewController alloc] init]; UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifthVC]; fifthNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1003] autorelease]; fifthNAVC.tabBarItem.badgeValue = @"+5"; sixthViewController *sixVC = [[sixthViewController alloc] init]; UINavigationController *sixNAVC = [[UINavigationController alloc] initWithRootViewController:sixVC]; sixNAVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1004] autorelease]; sixNAVC.tabBarItem.badgeValue = @"+6"; // UITabBarController *tab = [[UITabBarController alloc] init]; tab.viewControllers = @[firstnaVC, secNAVC, thirdNAVC, fourNAVC, fifthNAVC, sixNAVC]; self.window.rootViewController = tab; // 设置外观tabbar tab.tabBar.translucent = NO; // 背景颜色 tab.tabBar.barTintColor = [UIColor purpleColor]; // 选中后的图标颜色 tab.tabBar.tintColor = [UIColor blackColor]; // 默认所在位置 tab.selectedIndex = 2; // 签订协议 tab.delegate = self; [tab release]; [firstnaVC release]; [firstVC release]; [secVC release]; [secNAVC release]; [thirdVC release]; [thirdNAVC release]; [fourNAVC release]; [fourVC release]; [fifthNAVC release]; [fifthVC release]; [sixNAVC release]; [sixVC release]; return YES; } - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { NSLog(@"%ld", tabBarController.selectedIndex); // viewController.tabBarItem.badgeValue = nil; // 大红点 viewController.tabBarItem.badgeValue = @""; }
firstViewController.h
#import <UIKit/UIKit.h> @interface firstViewController : UIViewController @end
firstViewController.m
#import "firstViewController.h" #import "testViewController.h" @interface firstViewController () @end @implementation firstViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor lightGrayColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(100, 100, 150, 50); [button setTitle:@"推出下一页" forState:UIControlStateNormal]; [self.view addSubview:button]; button.layer.borderWidth = 1; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } - (void)buttonAction:(UIButton *)button { testViewController *testVC = [[testViewController alloc] init]; // 推出下一页则隐藏tabbar, 写在推出之前, 目标页面设置这个属性是YES testVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:testVC animated:YES]; [testVC release]; }
testViewcontroller.h
#import <UIKit/UIKit.h> @interface testViewController : UIViewController @end
testViewcontroller.m
#import "testViewController.h" @interface testViewController () @end @implementation testViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; }
SecondViewController ~~~sixthViewController, 依次
相关文章推荐
- UI_UITableView的HeaderView
- UI12_UIView动画
- UI:数据库练习、滤镜效果
- Leetcode NO.232 Implement Queue using Stacks
- UI11_UITableViewController
- UI11_TableView编辑
- 【白痴弟弟和你加强应用层】阅读 Develop API Guides 思考(一个)
- UI11_数据处理
- UI_UITableViewCell自适应高度(图片,字体)
- UI10_省市区分区跳转版
- SpriteBuilder中时间线播放音效的弊端
- SpriteBuilder中时间线播放音效的弊端
- SpriteBuilder中时间线播放音效的弊端
- UITableView中的一些坑
- SpriteBuilder中音频波长超过Timeline结尾的情况
- SpriteBuilder中音频波长超过Timeline结尾的情况
- SpriteBuilder中音频波长超过Timeline结尾的情况
- 2015/10/4 iOS 笔记 细节 简单-代理过程 UITableView
- HDOJ 题目5496 Beauty of Sequence(数学)
- iOS UISwitch用法和示例