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

iOS App開發(fā)中導(dǎo)航欄的創(chuàng)建及基本屬性設(shè)置教程

 更新時間:2016年02月26日 09:12:58   作者:蘋果吧  
這篇文章主要介紹了iOS App開發(fā)中導(dǎo)航欄的創(chuàng)建及基本屬性設(shè)置教程,即用UINavigationController來編寫navigation,示例代碼為Objective-C語言,需要的朋友可以參考下

文件目錄如下:基本導(dǎo)航順序: root -> First -> Second -> Third。其中,F(xiàn)irstViewController作為 navigation堆棧的rootview

201622690834116.jpg (229×371)

1、創(chuàng)建navigation

如果是想直接把navigation導(dǎo)航作為項目一開始的跟視圖,把RootViewController.h文件里的nav屬性放到AppDelegate.h里即可,再把RootViewController.m文件里的action的代碼復(fù)制到 AppDelegate.m里的didFinishLaunchingWithOptions 方法里,最后把 self.window.rootViewController 設(shè)置 UINavigationController類型的屬性nav即可

在RootViewController.h文件

復(fù)制代碼 代碼如下:

#import <UIKit/UIKit.h>
@class FirstViewController;

@interface RootViewController : UIViewController

@property (strong, nonatomic) UINavigationController *nav;

- (IBAction)btnClick:(UIButton *)sender;

@end


在RootViewController.m 文件里的隨意一個自定義action里:
復(fù)制代碼 代碼如下:

- (IBAction)btnClick:(UIButton *)sender {
   
    //創(chuàng)建一個viewcontroller
    FirstViewController *fristview =[[[FirstViewController alloc] init] autorelease];
  
   
    //初始化UINavigationController(方式一)
    self.nav = [[[UINavigationController alloc] initWithRootViewController:fristview] autorelease];
   
   
    //初始化UINavigationController(方式二)
  //  self.nav = [[[UINavigationController alloc] init] autorelease];
  //  [self.nav pushViewController:fristview animated:YES];

   
    //初始化UINavigationController(方式三,失敗,xib文件加載失敗,原因暫時不明)
   // self.nav = [[[UINavigationController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
   
   
    //跳轉(zhuǎn)到FirstView頁面
    [self presentViewController:self.nav animated:YES completion:nil];
   
   
    //這種寫法一般用于往view里添加一些小控件,如button  label textField之類的,不適宜用于頁面跳轉(zhuǎn)
    // [self.view addSubview:self.nav.view];
   
   
}

2.navigation的常用屬性設(shè)置例子
我們的navigation就加載上去了以后,下面我們來設(shè)置navigation的屬性:

復(fù)制代碼 代碼如下:

- (void)viewDidLoad 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    [self.navigationController.navigationBar setTranslucent:NO];//設(shè)置navigationbar的半透明 
    self.title = @"navigationcontroller";//設(shè)置navigationbar上顯示的標(biāo)題 
    [self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];//設(shè)置navigationbar的顏色 
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:Nil];//設(shè)置navigationbar左邊按鈕 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:Nil];//設(shè)置navigationbar右邊按鈕 
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];//設(shè)置navigationbar上左右按鈕字體顏色 


效果圖如下:

201622690858466.png (321×128)

這里還有一個屬性常用,就是:

復(fù)制代碼 代碼如下:

NSArray *arr = [NSArray arrayWithObjects:@"1",@"2", nil nil]; 
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:arr]; 
    self.navigationItem.titleView = segment;//設(shè)置navigation上的titleview 

效果如下:

201622690937588.png (317×112)

對,我們看到中間的字變成了兩個可選的按鈕,這就是navigation的另一個屬性:navigationitem.titleview。

下面我們再建立一個視圖,看一下兩個視圖之前是怎樣通信的。

在第二個視圖中,我添加了一個button來顯示,并加了一個成員變量來接收從第一個視圖中穿過來的值:
 

復(fù)制代碼 代碼如下:

@interface SecondViewController : UIViewController 
@property (copy,nonatomic) NSString *str; 
@end 
 

復(fù)制代碼 代碼如下:

- (void)viewDidLoad 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.title = @"second"; 
    UIButton *aBUTTON = [[UIButton alloc]initWithFrame:CGRectMake(30, 30, 50, 30)]; 
    [aBUTTON setTitle:_str forState:UIControlStateNormal]; 
    [aBUTTON addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:aBUTTON]; 


然后我將第一個視圖的右邊按鈕添加一個事件,點擊按鈕,就會推出第二個視圖,并顯示我們傳過來的值:
 
復(fù)制代碼 代碼如下:

- (void)clicked{ 
    SecondViewController *second = [[SecondViewController alloc]init]; 
    [self.navigationController pushViewController:second animated:YES]; 
    second.str = @"hello!!"; 
    [second release]; 


下面,我們來運行一下:

201622691003542.png (316×162)

點進按鈕以后,我們的第二個視圖推出,button顯示了傳過來的值。

然后我們點擊回button,還有navigation另外一個方法:

復(fù)制代碼 代碼如下:

- (void)clicked{ 
    [self.navigationController popViewControllerAnimated:YES]; 


這樣就可以回到第一個視圖。
 

相關(guān)文章

  • Flutter CustomPaint自定義繪畫示例詳解

    Flutter CustomPaint自定義繪畫示例詳解

    這篇文章主要為大家介紹了Flutter CustomPaint自定義繪畫示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • IOS應(yīng)用內(nèi)跳轉(zhuǎn)系統(tǒng)設(shè)置相關(guān)界面的方法

    IOS應(yīng)用內(nèi)跳轉(zhuǎn)系統(tǒng)設(shè)置相關(guān)界面的方法

    在iOS開發(fā)中,有時會有跳轉(zhuǎn)系統(tǒng)設(shè)置界面的需求,例如提示用戶打開藍牙或者WIFI,提醒用戶打開推送或者位置權(quán)限等,接下來通過本文給大家介紹IOS應(yīng)用內(nèi)跳轉(zhuǎn)系統(tǒng)設(shè)置相關(guān)界面的方法,喜歡的朋友參考下
    2016-02-02
  • 最新評論