UINavigationController 導(dǎo)航欄

  • AppDelegate.m
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

RootViewController *root = [[RootViewController alloc] init];

//標(biāo)題(中間位置)
root.title = @"首頁";


//創(chuàng)建導(dǎo)航欄控制器
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:root];

self.window.rootViewController = navController;

[_window makeKeyAndVisible];







leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(selectLeft:)];

self.navigationItem.leftBarButtonItem = leftButton; // 左邊的button

rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRight:)];

self.navigationItem.rightBarButtonItem = rightButton; // 右邊的button



AddViewController *add = [[AddViewController alloc] init]; // 右button點(diǎn)擊事件
    
//修改字體啥的
self.navigationItem.title = @"返回";

[self.navigationController pushViewController:add animated:YES];
導(dǎo)航欄button樣式
  • AddViewController.m
self.view.backgroundColor = [UIColor greenColor];

self.title = @"第二頁";
首頁

點(diǎn)擊右上角的加號,會進(jìn)入第二頁。

第二頁

點(diǎn)擊返回,到第一頁。

self.navigationItem.prompt = @"歡迎訪問www.baidu.com"; //文本顯示在導(dǎo)航欄按鈕(在最上方)
顯示網(wǎng)址的樣子
動畫效果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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