代码之家  ›  专栏  ›  技术社区  ›  user4992124

更改iOS 11大标题颜色

  •  9
  • user4992124  · 技术社区  · 8 年前

    我试着做:

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

    6 回复  |  直到 8 年前
        1
  •  24
  •   David Knight    8 年前
    self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; 
    
        2
  •  15
  •   Kevin Furman    7 年前

    我认为这仍然是Xcode 9 beta 6中的一个bug。

    我找到了不同的“解决方案”:

    1. 如果将其放入AppDelegate,则可以更改标题的颜色:
        if #available(iOS 11.0, *) {
          UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue]
        }
    
        if #available(iOS 11.0, *) {            
          self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 31, weight: UIFont.Weight.bold) ]
        }
    

    当做

        3
  •  2
  •   Community CDub    5 年前

    enter image description here

    目标-C

    if (@available(iOS 11.0, *)) {
        self.navigationController.navigationItem.largeTitleDisplayMode =  UINavigationItemLargeTitleDisplayModeAlways;
        self.navigationController.navigationBar.prefersLargeTitles = true;
    
    // Change Color
        self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
    
    } else {
        // Fallback on earlier versions
    }
    
        4
  •  1
  •   Community CDub    5 年前

    Swift 4.2

    self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
    

    self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor(named: "Teal") ?? UIColor.black]
    
        5
  •  0
  •   bubbaspike    6 年前

            self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    
        6
  •  0
  •   kobeli    3 年前
      let largeTitleTextAttributes: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.gray20, .font: UIFont.systemFont(ofSize: 24.0, weight: .bold)]
        if #available(iOS 15, *) {
                    let navigationBar = navigationController.navigationBar
                    let appearance = navigationBar.standardAppearance
                        appearance.largeTitleTextAttributes = largeTitleTextAttributes
                        navigationBar.standardAppearance = appearance
                        navigationBar.scrollEdgeAppearance = appearance
                } else {
                        navigationController.navigationBar.largeTitleTextAttributes = largeTitleTextAttributes
                }