Change font of prompt in UINavigationController

吃可爱长大的小学妹 提交于 2021-02-08 08:41:05

问题


can someone help me out in changing font, size and color in prompt string on my NavigationController?

In the attachment, I want to modify "Consulenze" string. Thank you everybody

Edit: I already tried the solution found here but no results.


回答1:


You can try following ways: 1) In viewDidLoad of your ViewController add this lines:

self.navigationController?.navigationBar.tintColor = UIColor.white

let navigationTitleFont = UIFont(name: "Avenir", size: 20)!

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: navigationTitleFont]

2) You can create completely custom nav bar, just add UIView to the top your view and add all necessary elements - buttons, labels, etc.




回答2:


Simply add this code in your ViewController. You can change both the Prompt text and color by using this code -

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    override func viewWillAppear(_ animated: Bool) {

        for view in self.navigationController?.navigationBar.subviews ?? [] {
            let subviews = view.subviews
            if subviews.count > 0, let label = subviews[0] as? UILabel {
                label.textColor = UIColor.red
                label.font = UIFont.systemFont(ofSize: 30)
            }
        }
    }
}

OUTPUT -

Additional -



来源:https://stackoverflow.com/questions/49455068/change-font-of-prompt-in-uinavigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!