UINavigationBar背景,標(biāo)題和返回按鈕文字顏色

更改導(dǎo)航欄的背景和文字顏色

//設(shè)置NavigationBar背景顏色
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
//@{}代表Dictionary
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

設(shè)置導(dǎo)航條Item內(nèi)容

UIBarButtonItem *item =[[UIBarButtonItem alloc] initWithTitle:@"右邊" style:UIBarButtonItemStyleDone target:self action:@selector(click)];
self.navigationItem.rightBarButtonItem = item;

在iOS7之后,系統(tǒng)默認(rèn)會(huì)把導(dǎo)航條上的圖片渲染成藍(lán)色.
如何不渲染圖片,告訴系統(tǒng)我這個(gè)圖片不要渲染

UIImage *image = [UIImage imageNamed:@"navigationbar_friendsearch"];
// 返回一個(gè)最原始的圖片
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// 創(chuàng)建一個(gè)按鈕
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:image forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted];
// 導(dǎo)航條上按鈕尺寸可以由自己決定
// 導(dǎo)航條上的內(nèi)容位置由系統(tǒng)決定
btn.frame = CGRectMake(2000, 0, 35, 35);
// 導(dǎo)航條的內(nèi)容顯示兩張圖片
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem = item1;

通過設(shè)置navigationItem的backBarButtonItem可以直接更換文字

【注意,要在父視圖的Controller中設(shè)置】如下:
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = item;

設(shè)置顏色

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

最后編輯于
?著作權(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)容