UINavigationController

UINavigationController 導(dǎo)航控制器
其實就是


導(dǎo)航控制器.png

這玩意

AppDelegate.m

RootViewController *rvc = [[RootViewController alloc] init];
// 導(dǎo)航控制器至少要有一個視圖控制器 這個控制器就是導(dǎo)航控制器的根視圖控制器
UINavigationController *rootNAC = [[UINavigationController alloc] initWithRootViewController:rvc];

RootViewController.m

//設(shè)置導(dǎo)航欄的顏色,對navigationController的設(shè)置會將這個控制器關(guān)聯(lián)的視圖控制器的對應(yīng)屬性都一次性改變
self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
//設(shè)置標(biāo)題
self.navigationItem.title = @"主界面";
//自定義導(dǎo)航欄中間標(biāo)題
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"呵呵",@"哈哈"]];
segment.frame = CGRectMake(0,0,100,30);//位置固定在導(dǎo)航欄中間的
self.navigationItem.titleView = segment;
[segment release];

// 設(shè)置導(dǎo)航欄的透明度,默認(rèn)是YES
// 當(dāng)透明度為YES時,那么視圖控制器的零點就在屏幕的最左上角,如果是NO,零點就在導(dǎo)航欄的最左下角處
// 豎屏?xí)r,導(dǎo)航欄是44?單位+狀態(tài)欄20單位 一共是64單位高
// 橫屏?xí)r,導(dǎo)航欄是32單位+狀態(tài)欄20單位 一共是52單位高
self.navigationController.translucent = NO;
// 系統(tǒng)自帶樣式的barButton
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(leftbuttonAction:)];
self.navigationItem.leftBarButtonItem = leftBarButton;
[leftBarButtonA release];
// 自己設(shè)置圖片形式的barButton
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"test.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightbuttonAction:)];
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];
// 設(shè)置所有導(dǎo)航欄上按鈕的顏色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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