簡體   English   中英

目標C:如何在導航欄中更改文本顏色

[英]Objective C: How to change text color in navigation bar

我通過以下代碼更改了導航欄顏色

navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];

代碼工作但文本顏色也需要更改(見下面的截圖)。 此外,右側的刷新按鈕徽標也會受到影響

在此輸入圖像描述

如果我導航到堆棧中的另一個頁面,則會出現同樣的問題

在此輸入圖像描述

問題:如何更改顏色

  • 標題文字
  • 后退按鈕文本和
  • 右欄按鈕圖標顏色?

我改變了導航欄的背景顏色后?

在iOS 7中,只需使用:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

使用您想要的任何文本顏色更改[UIColor whiteColor]

這里的標題是這樣的:

iPhone導航欄標題文字顏色

對於自定義按鈕,這里的方式是:

添加按鈕到ui導航控制器底欄

要更改文字顏色:

_navController.navigationBar.titleTextAttributes 
         = @{UITextAttributeTextColor : [UIColor blackColor]};

添加刷新按鈕並為其着色:

UIBarButtonItem *button = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
         target:self action:@selector(reload)];

[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;

影響導航欄背景的變量:

_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;

我只是將一個簡單的UIViewController子類放在一起,它添加了一個可自定義的后退按鈕,允許您更改文本顏色。 它基本上添加了一些willAppear / willDisappear邏輯來設置后退按鈕的動畫,就像UINavigationController在使用leftBarButtonItem屬性時一樣。 您也可以將其擴展為也執行rightBarButtomItem。

https://github.com/typeoneerror/BBCustomBackButtonViewController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM