亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iOS 7導航欄文本和箭頭顏色

iOS 7導航欄文本和箭頭顏色

繁星淼淼 2020-02-03 14:52:06
我想將導航欄的背景設置為黑色,并將其中的所有顏色設置為白色。因此,我使用了以下代碼:[[UINavigationBar appearance] setTitleTextAttributes:     [NSDictionary dictionaryWithObjectsAndKeys:      [UIColor whiteColor],      NSForegroundColorAttributeName,      [UIColor whiteColor],      NSForegroundColorAttributeName,      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],      NSForegroundColorAttributeName,      [UIFont fontWithName:@"Arial-Bold" size:0.0],      NSFontAttributeName,      nil]];但是后退按鈕的文字顏色,箭頭和方向鍵仍為默認藍色。如何更改下圖所示的顏色?
查看完整描述

3 回答

?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

UINavigationBar從iOS 7開始,某些屬性的行為已更改。您可以在下面顯示的圖像中看到:

我想與您分享兩個美麗的鏈接。有關更多詳細信息,您可以通過以下鏈接:


iOS 7 UI過渡指南。

如何為iOS更新您的應用程序7。

蘋果文檔的barTintColor說:


除非您將半透明屬性設置為NO,否則默認情況下此顏色為半透明。


樣例代碼:


self.navigationController.navigationBar.barTintColor = [UIColor blackColor];

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

[self.navigationController.navigationBar 

 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

self.navigationController.navigationBar.translucent = NO;


查看完整回答
反對 回復 2020-02-03
?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

這花了我大約半天時間才弄清楚,但這對我有用。在用于初始化navigationController的rootViewController中,將以下代碼放入viewDidAppear方法中:


//set bar color

[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];

//optional, i don't want my bar to be translucent

[self.navigationController.navigationBar setTranslucent:NO];

//set title and title color

[self.navigationItem setTitle:@"Title"];

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];

//set back button color

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];

//set back button arrow color

[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];


查看完整回答
反對 回復 2020-02-03
?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

Swift3,iOS 10


要全局分配顏色,請在AppDelegate中didFinishLaunchingWithOptions:


let textAttributes = [NSForegroundColorAttributeName:UIColor.white]

UINavigationBar.appearance().titleTextAttributes = textAttributes

Swift 4,iOS 11


let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]

UINavigationBar.appearance().titleTextAttributes = textAttributes


查看完整回答
反對 回復 2020-02-03
  • 3 回答
  • 0 關注
  • 1042 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號