iOS開發(fā)之UI(七)

1.UINavigationController

UINavigationController(導(dǎo)航視圖控制器):管理控制器的控制器,主要管理有層次遞進(jìn)關(guān)系的控制器,以棧的方式管理所控制的視圖控制器,至少要由一個(gè)被管理的試圖控制器,這個(gè)視圖控制器叫導(dǎo)航視圖控制器的根視圖控制器

創(chuàng)建方法,在Appdelegate.m中創(chuàng)建

ViewController *VC = [[ViewController alloc] init];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:VC];
self.window.rootViewController = naVC;

2.UINavigationBar

UINavigationBar(導(dǎo)航欄):iOS7之后默認(rèn)是半透明,iOS7之前默認(rèn)是不透明的。豎屏下默認(rèn)高度44,橫屏下默認(rèn)高度32。iOS7之后,navigationBar的背景會(huì)延生到statusBar上,所以顯示效果為64。每個(gè)視圖控制器都有一個(gè)navigationItem屬性,在其中設(shè)置左按鈕、右按鈕、標(biāo)題等,會(huì)隨著控制器的顯示,也顯示到navigationBar上

導(dǎo)航欄屬性

self.navigationItem.title = @"標(biāo)題";// 創(chuàng)建單個(gè)titile
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];// 創(chuàng)建單個(gè)leftBarButtonItem
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];// 創(chuàng)建單個(gè)rightBarButtonItem
/*
// 創(chuàng)建多個(gè)titles
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"我", @"你"]];
segmentedControl.frame = CGRectMake(0, 0, 100, 30);
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;

// 創(chuàng)建多個(gè)BarButtonItems
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
self.navigationItem.leftBarButtonItems = @[item1, item2];
self.navigationItem.rightBarButtonItems = @[item1, item2];

// UINavigationBar屬性
self.navigationController.navigationBarHidden = NO;// 顯隱性
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;// 樣式
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];;// 背景顏色
//self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];// 前景顏色
self.navigationController.navigationBar.tintColor = [UIColor blackColor];// 元素顏色
 */

/**
 *  半透明效果開啟時(shí),坐標(biāo)原點(diǎn)為(0, 0)
    半透明效果關(guān)閉時(shí),坐標(biāo)原點(diǎn)為(64, 0)
 */
self.navigationController.navigationBar.translucent = YES;// 半透明效果,iOS7以后默認(rèn)為YES

3.頁(yè)面跳轉(zhuǎn)

導(dǎo)航視圖控制器push

- (void)add {
    BlueViewController *blueVC = [[BlueViewController alloc] init];
    [self.navigationController pushViewController:blueVC animated:YES];// 使用導(dǎo)航視圖控制器推出blueVC
}

模態(tài)推出

- (void)save {
    BlueViewController *blueVC = [[BlueViewController alloc] init];
    [self presentViewController:blueVC animated:YES completion:nil];// 模態(tài)推出blueVC
}

返回方法

- (void)back {
    //[self.navigationController popToRootViewControllerAnimated:YES];// 返回根視圖控制器
    //[self.navigationController popViewControllerAnimated:YES];// 返回上一個(gè)視圖控制器
    [self dismissViewControllerAnimated:YES completion:nil];// 模態(tài)返回上一頁(yè)

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容