簡體   English   中英

如何改變iOS7的按鈕顏色

[英]how to change backbutton color iOS7

我已經為iOS7開發了一款具有這種設計的應用程序

在此輸入圖像描述

你可以看到我的所有BackButton都有一個藍色箭頭(使用UINavigationController和segues),我想把它們變成紅色,這是我的代碼:

[UIBarButtonItem   appearance]setTintColor:(UIColorFromRGB(toolbarTintColor))];
[[UIBarButtonItem  appearance]setTitleTextAttributes:textAtributesDictionaryNavBarButtons forState:UIControlStateNormal];

但結果只適用於所有其他按鈕,任何幫助,我會很感激

在此先感謝您的支持

導航欄的色調屬性確定iOS 7中其條形按鈕項的文本顏色。您要查找的代碼如下所示:

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

當然,用你想要的任何顏色替換[UIColor redColor]

將此代碼放入App Delegate中:

Objective-C的

[self.window setTintColor:[UIColor redColor]];

迅速

self.window?.tintColor = UIColor.redColor()

如果您不想更改整個應用程序中的色調顏色,只想在一個導航欄上執行此操作,請執行以下操作:

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

如果你想要swift版本。

UINavigationBar.appearance().tintColor = UIColor.whiteColor()

此外,如果要將此樣式應用於所有導航視圖控制器。 將該代碼放在AppDelegate中的應用程序didFinishLaunchingWithOptions方法中

迅速:

self.navigationController?.navigationBar.tintColor = UIColor.grayColor()
  • 如果您正在使用故事板,那么您需要在類檢查器窗格下為keyPath“tintColor”添加用戶定義的屬性。
  • 因為在最新版本的Interface builder中刪除了靜態tintColor屬性。 單擊“+”,在KeyPath中添加tintColor,設置“類型”顏色並添加顏色。

您可以直接在IB中設置它:

在此輸入圖像描述

-(void)viewDidAppear:(BOOL)animated
{
   //set back button color
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    //set back button arrow color
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}

暫無
暫無

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

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