0: 首先還是通過純的代碼來實現
0:刪除3個檔案ViewController.h,ViewController.m,Main.storyboard
1:修改點擊左邊的藍色按鈕,然後選擇general-》developer info-》main interface ,將這個main interface 晴空
1: 然後產生四個視圖控制器First Second Third Fourth,和一個類別
FirstViewController:
//// FirstViewController.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "FirstViewController.h"#import "FourthViewController.h"@interface FirstViewController ()@end@implementation FirstViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setTitle:@"First"]; [self.view setBackgroundColor:[UIColor yellowColor]]; NSLog(@"first: %s",__func__);//列印方法名字 //添加一個push按鈕,然後點擊之後讓地步的導覽列也不顯示 self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"PUSH" style:UIBarButtonItemStylePlain target:self action:@selector(pushController)];}-(void)pushController{ FourthViewController *fourthVC = [[FourthViewController alloc]init]; //隱藏下面的標籤欄 [fourthVC setHidesBottomBarWhenPushed:YES]; [self.navigationController pushViewController:fourthVC animated:YES];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
SecondViewController
//// SecondViewController.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "SecondViewController.h"@interface SecondViewController ()@end@implementation SecondViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setTitle:@"Second"]; [self.view setBackgroundColor:[UIColor redColor]]; NSLog(@"second: %s",__func__);//列印方法名字}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
ThirdViewController
//// ThirdViewController.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "ThirdViewController.h"@interface ThirdViewController ()@end@implementation ThirdViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setTitle:@"Third"]; [self.view setBackgroundColor:[UIColor blueColor]]; NSLog(@"third: %s",__func__);//列印方法名字}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
FourthViewController
//// FourthViewController.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "FourthViewController.h"@interface FourthViewController ()@end@implementation FourthViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setTitle:@"Fourth"]; [self.view setBackgroundColor:[UIColor brownColor]];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
UIImage+OriginalImage
//// UIImage+OriginalImage.h// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import <UIKit/UIKit.h>//預設上面的圖片都是做過了毛玻璃的效果的,如果不想要毛玻璃的效果,那麼久直接@interface UIImage (OriginalImage)+(UIImage *) originalImageName:(NSString *)name;@end
//// UIImage+OriginalImage.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "UIImage+OriginalImage.h"@implementation UIImage (OriginalImage)//預設上面的圖片都是做過了毛玻璃的效果的,如果不想要毛玻璃的效果,那麼久直接+(UIImage *) originalImageName:(NSString *)name{ return [[UIImage imageNamed:name]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];}@end
2: 然後修改app delegate.m檔案
//// AppDelegate.m// EllevenBiaoqianLan//// Created by 千雅爸爸 on 16/10/27.// Copyright © 2016年 kodulf. All rights reserved.//#import "AppDelegate.h"#import "FirstViewController.h"#import "SecondViewController.h"#import "ThirdViewController.h"//預設上面的圖片都是做過了毛玻璃的效果的,如果不想要毛玻璃的效果,那麼久直接//匯入我們建立的分類#import "UIImage+OriginalImage.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //導覽列控制器是一種棧的形式, //標籤欄控制器,就有點像是android 裡面的ViewPager和RadioGroup結合的形式,但是又是不同的,標籤欄控制器裡面的組件,例如有導覽列控制器,有其它的,會都顯示只不過是有的在前面,有的在後面,相當於是並列的顯示,請查看說明的圖 //我們一板是將導覽列控制器設定為標籤欄控制器的子控制器 //首先建立四個控制器的類,然後是一個UIImage+OriginalImage的分類 [self setWindow:[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]]; [self.window makeKeyAndVisible]; UITabBarController *tabBarController = [[UITabBarController alloc] init]; [tabBarController.view setBackgroundColor:[UIColor whiteColor] ]; [self.window setRootViewController:tabBarController]; FirstViewController *firstVC=[[FirstViewController alloc]init]; //把first先放在navigationcontroler上面,然後再將navigationcontroller添加到 firstVC.tabBarItem.title = @"first";//地下的說明的文字 firstVC.tabBarItem.image = [UIImage imageNamed:@"64"];//預設的圖片 //firstVC.tabBarItem.selectedImage =[UIImage imageNamed:@"cat"];//選中後的效果 //預設上面的圖片都是做過了毛玻璃的效果的,如果不想要毛玻璃的效果,那麼久直接 //這裡的選中和補選中的顯示就和android 中的selector很像 firstVC.tabBarItem.selectedImage =[UIImage originalImageName:@"cat"];//選中後的效果 UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstVC]; //直接複製粘貼上面的first 產生second third SecondViewController *secondVC = [[SecondViewController alloc]init]; secondVC.tabBarItem.title =@"second"; secondVC.tabBarItem.image = [UIImage imageNamed:@"64"]; secondVC.tabBarItem.selectedImage=[UIImage originalImageName:@"cat"]; UINavigationController *secondNavigationController = [[UINavigationController alloc]initWithRootViewController:secondVC]; ThirdViewController *thirdVC = [[ThirdViewController alloc]init]; thirdVC.tabBarItem.title = @"third"; thirdVC.tabBarItem.image =[UIImage imageNamed:@"64"]; thirdVC.tabBarItem.selectedImage = [UIImage originalImageName:@"cat"]; UINavigationController *thirdNavigationController = [[UINavigationController alloc]initWithRootViewController:thirdVC]; //還可以給tabbar 設定背景圖片和顏色 [tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"green2"]]; //[tabBarController.tabBar setBackgroundColor:[UIColor greenColor]]; //統一設定字型的大小 [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} forState:UIControlStateNormal]; [tabBarController setViewControllers:@[navigationController,secondNavigationController,thirdNavigationController]]; //預設的tabbar選擇的是第一個被加入到數組中的 //懶載入的方式,用到哪個就去加在哪個,而且一旦載入了不會輕易的被回收 //但是如果出現記憶體警告了,那麼系統會優先處理掉那些當前用不到的介面 // 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