欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)中UITabBarController的使用示例

 更新時間:2015年09月24日 10:11:01   作者:TommyYaphetS  
這篇文章主要介紹了iOS開發(fā)中UITabBarController的使用示例,代碼基于Objective-C進行演示,需要的朋友可以參考下

首先我們看一下它的view層級圖:

復制代碼 代碼如下:

- (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]; 
  
#pragma mark - 設置tabBarItem 
#pragma mark  第一個視圖ViewController 
     
    HMT_AViewController * tabBarViewA = [[HMT_AViewController alloc] init]; 
    // 設置A視圖下----標簽欄標題文字(可參照微信或者QQ體會) 
    tabBarViewA.tabBarItem.title = @"微信"; 
    // 設置A視圖下----標簽欄圖片(因為自己沒有圖片,在這里隨便設置了個名字) 
    //tabBarViewA.tabBarItem.image = [UIImage imageNamed:@"1.png"]; 
    // 設置A視圖下----標簽欄信息提示(住:badgeValue是NSString類型 如下設置了3,就像QQ消息有3條未接受一樣,給人一種提醒) 
    tabBarViewA.tabBarItem.badgeValue = @"3"; 
    // ios7棄用了----標簽欄選中的時候顯示一張圖片,沒選中的時候顯示另一張圖片 
    //[tabBarViewA.tabBarItem setFinishedSelectedImage:actionMenu.selectedIcon withFinishedUnselectedImage:actionMenu.icon]; 
    // ios7的方法(自己沒有圖片,所以代碼里面的圖片都是一個隨便取的名字,沒有實用意義) 
    //tabBarViewA.tabBarItem.selectedImage = actionMenu.selectedIcon; 
     
#pragma mark  第二個視圖ViewController 
    // 第二個視圖ViewController 
    HMT_BViewController * tabBarViewB = [[HMT_BViewController alloc] init]; 
    // 設置B視圖下----標簽欄 
    // 用系統(tǒng)提供的標識(可以算等價于圖標和文字)進行設置(參數(shù):UITabBarSystemItem是個枚舉值,想要什么形式,就去系統(tǒng)提供的API中找) 
    tabBarViewB.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1]; 
    // 設置B視圖下----標簽欄信息提示 
    tabBarViewB.tabBarItem.badgeValue = @"GO"; 
     
#pragma mark  第三個視圖ViewController 
    HMT_CViewController * tabBarViewC = [[HMT_CViewController alloc] init]; 
    tabBarViewC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:2]; 
    // 設置B視圖下----標簽欄信息提示 
    tabBarViewC.tabBarItem.badgeValue = @"new"; 
     
#pragma mark  第四個視圖ViewController 
    HMT_DViewController * tabBarViewD = [[HMT_DViewController alloc] init]; 
    tabBarViewD.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3]; 
    // 設置B視圖下----標簽欄信息提示 
    tabBarViewD.tabBarItem.badgeValue = @"99"; 
     
#pragma mark  第五個視圖ViewController 
    HMT_EViewController * tabBarViewE = [[HMT_EViewController alloc] init]; 
    tabBarViewE.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:4]; 
    // 設置B視圖下----標簽欄信息提示 
    tabBarViewE.tabBarItem.badgeValue = @"sky"; 
     
#pragma mark  第六個視圖ViewController(系統(tǒng)默認能顯示的最大視圖個數(shù)是5個) 
    /* 如果你的viewControllers屬性添加了多于五個的items,那tab bar controller將會自動插入一個特殊的view controller,
    稱為 More view controller,該 controller 將會負責管理多于的items,這個More view controller提供一個自定義的界面,
    用table的方式呈現(xiàn)多余的view controller,并且view controller的數(shù)量是不限制的*/ 
    HMT_FViewController * tabBarViewF = [[HMT_FViewController alloc] init]; 
    tabBarViewF.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:5]; 
    // 設置F視圖下----標簽欄信息提示 
    tabBarViewF.tabBarItem.badgeValue = @"AG"; 
     
     
     
#pragma mark - 設置TabBarController 
     
    // 創(chuàng)建TabBarController 
    UITabBarController * tabBarController = [[UITabBarController alloc]init]; 
    // TabBarController默認是放在最底部的,如果你想調(diào)整位置,可以進行下面2部操作(44是iPhone中TabBarController和UINavigationController標準高度) 
    //CGRect frame = CGRectMake(0, 20, 320, 44); 
    //tabBarController.tabBar.frame = frame; 
    // 每一個tab都必須有一個content view controller------->viewControllers屬性,用來存入一個應用的TabBarController有多少個界面切換 
    tabBarController.viewControllers = [NSArray arrayWithObjects:tabBarViewA,tabBarViewB,tabBarViewC,tabBarViewD,tabBarViewE,tabBarViewF, nil nil]; 
    // 設置著色 
    tabBarController.tabBar.tintColor = [UIColor greenColor]; 
    // 設置選中圖片時候 
    tabBarController.tabBar.selectedImageTintColor = [UIColor brownColor]; 
    // 設置背景圖片(自己沒有圖片,不進行設置) 
    //tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"@@@@@"]; 
    // 設置程序啟動時默認的ViewController視圖(設置為3,一共5個ViewController,進來時候顯示的視圖就是第4個-tabBarViewD,下標從0開始) 
    tabBarController.selectedIndex = 3; 
     
     
    self.window.rootViewController = tabBarController; 
     
    [self.window makeKeyAndVisible]; 
    return YES; 

最后效果如下圖:

UITabBarController的代理方法以及模態(tài)顯示
首先要實現(xiàn)協(xié)議<UITabBarControllerDelegate>

復制代碼 代碼如下:
    // 設置代理
    tabBarController.delegate =self; 
    //UINavigationController *nav = tabBarController.moreNavigationController;
    //[nav setNavigationBarHidden:YES animated:YES];

// 控制哪些ViewController的標簽欄能被點擊
- (BOOL)tabBarController:(UITabBarController *)tabBarControllershouldSelectViewController:(UIViewController *)viewController{
    // 代表HMT_CViewController這個View無法顯示,無法點擊到它代表的標簽欄
    if ([viewControllerisKindOfClass:[HMT_CViewControllerclass]]) {
        returnNO;
    }
    returnYES;
}

// 選中哪個標簽欄,一個監(jiān)控作用吧
- (void)tabBarController:(UITabBarController *)tabBarControllerdidSelectViewController:(UIViewController *)viewController{

}

// More view controller將要開始編輯
- (void)tabBarController:(UITabBarController *)tabBarControllerwillBeginCustomizingViewControllers:(NSArray *)viewControllers{

}
// More view controller將要結(jié)束編輯
- (void)tabBarController:(UITabBarController *)tabBarControllerwillEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{

}
// More view controller編輯
- (void)tabBarController:(UITabBarController *)tabBarControllerdidEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{

}

#import "HMT-AViewController.h"
#import "HMTModalShowViewController.h"

@interfaceHMT_AViewController ()
@end

@implementation HMT_AViewController

- (void)viewDidLoad
{
    [superviewDidLoad];
    self.view.backgroundColor = [UIColorredColor];
   
    // 創(chuàng)建一個按鈕
    UIButton * button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    button.frame =CGRectMake(100,100,100, 100);
    [button addTarget:self action:@selector(modalShow)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
// Do any additional setup after loading the view.
}

- (void)modalShow{
   
    HMTModalShowViewController * modalShowVC = [[HMTModalShowViewController alloc]init];

    //模態(tài)視圖控制器呈現(xiàn)出來時候的視覺效果
    modalShowVC.modalTransitionStyle =UIModalTransitionStyleCrossDissolve;
    /*
     UIModalTransitionStyleCoverVertical = 0,   //默認,由下往上
     UIModalTransitionStyleFlipHorizontal,      //水平轉(zhuǎn)動效果
     UIModalTransitionStyleCrossDissolve,       //漸變效果
     UIModalTransitionStylePartialCurl,         //書頁往上翻動效果
     */
    //模態(tài)視圖控制器呈現(xiàn)方式,默認全屏
    modalShowVC.modalPresentationStyle =UIModalPresentationFullScreen;
    /*   
     UIModalPresentationFullScreen = 0,
     UIModalPresentationPageSheet,
     UIModalPresentationFormSheet,
     UIModalPresentationCurrentContext,
     UIModalPresentationCustom,
     UIModalPresentationNone = -1,   
     */
   
    UINavigationController * modalShowNC = [[UINavigationController alloc] initWithRootViewController:modalShowVC];
   
    //推出模態(tài)視圖控制器
    [self presentViewController:modalShowNC animated:YES completion:^{
        NSLog(@"hello world");      
    }];
}


#import "HMTModalShowViewController.h"

@interfaceHMTModalShowViewController ()

@end

@implementation HMTModalShowViewController

- (void)viewDidLoad
{
    [superviewDidLoad];
// Do any additional setup after loading the view.
   
    self.view.backgroundColor = [UIColor yellowColor];
   
    // 利用UINavigationController來實現(xiàn)退出控制器
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(modalDismiss)];
   
    self.navigationItem.leftBarButtonItem = barButton;
    self.navigationItem.title =@"humingtao";
   
    //創(chuàng)建一個按鈕來實現(xiàn)退出控制器
/*    UIButton * button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    button.frame = CGRectMake(100, 100, 100, 100);
    [button addTarget:self action:@selector(modalDismiss) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:button];*/
   
}

- (void)modalDismiss{
   //退出模態(tài)視圖控制器
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"退出GoodBye");
    }];
}
@end


相關(guān)文章

  • iOS百度地圖簡單使用詳解

    iOS百度地圖簡單使用詳解

    百度地圖的功能有很多,本篇文章主要介紹了iOS百度地圖簡單使用詳解,具有一定的參考價值,有需要的可以了解一下。
    2016-11-11
  • iOS如何自定義控制器轉(zhuǎn)場動畫push詳解

    iOS如何自定義控制器轉(zhuǎn)場動畫push詳解

    在平時開發(fā)中,有時候需要一些轉(zhuǎn)場動畫給界面調(diào)整增添一些活力,而實現(xiàn)這些動畫相對比較繁瑣。下面這篇文章主要給大家介紹了關(guān)于iOS如何自定義控制器轉(zhuǎn)場動畫push的相關(guān)資料,需要的朋友可以參考下。
    2017-12-12
  • 如何實現(xiàn)IOS_SearchBar搜索欄及關(guān)鍵字高亮

    如何實現(xiàn)IOS_SearchBar搜索欄及關(guān)鍵字高亮

    本文通過實例代碼演示如何實現(xiàn)IOS搜索欄及搜索關(guān)鍵字高亮,效果很棒,小編覺得對大家的學習會很有幫助,現(xiàn)在分享給大家,有需要的可以參考學習。
    2016-08-08
  • iOS工程中怎么判斷下載的流是PDF文件

    iOS工程中怎么判斷下載的流是PDF文件

    iOS工程中怎么判斷下載的流是PDF文件?下面小編就為大家分享一篇iOS工程中判斷下載的流是PDF文件的方法。希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • 在iOS10系統(tǒng)中微信后退無法發(fā)起ajax請求的問題解決辦法

    在iOS10系統(tǒng)中微信后退無法發(fā)起ajax請求的問題解決辦法

    這篇文章主要介紹了在iOS10系統(tǒng)中微信后退無法發(fā)起ajax請求的問題解決辦法,一般可以通過延時發(fā)送請求解決,下面通過本文給大家分享下解決辦法,需要的朋友參考下吧
    2017-01-01
  • iOS tableView右側(cè)索引視圖狀態(tài)獲取的方法實例

    iOS tableView右側(cè)索引視圖狀態(tài)獲取的方法實例

    tableView用于顯示一個垂直滾動的單元格數(shù)(通常為可重復使用的單元格)組成的視圖,這篇文章主要給大家介紹了關(guān)于iOS tableView右側(cè)索引視圖狀態(tài)獲取的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • iOS 設置狀態(tài)欄的背景顏色方法

    iOS 設置狀態(tài)欄的背景顏色方法

    下面小編就為大家?guī)硪黄猧OS 設置狀態(tài)欄的背景顏色方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • iOS?WKWebView秒開方案實戰(zhàn)記錄

    iOS?WKWebView秒開方案實戰(zhàn)記錄

    從iOS8開始,就引入了新的瀏覽器控件WKWebView,用于取代UIWebView,下面這篇文章主要給大家介紹了關(guān)于iOS?WKWebView秒開方案的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2021-12-12
  • iOS利用Label實現(xiàn)的簡單高性能標簽TagView

    iOS利用Label實現(xiàn)的簡單高性能標簽TagView

    這篇文章主要給大家介紹了關(guān)于iOS利用Label實現(xiàn)的簡單高性能標簽TagView的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2018-03-03
  • iOS 二維碼掃描和應用跳轉(zhuǎn)

    iOS 二維碼掃描和應用跳轉(zhuǎn)

    本文講解如何使用原生框架實現(xiàn)二維碼掃描功能,并且進行掃描后的項目跳轉(zhuǎn)。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-03-03

最新評論