Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change the text color of rightBarButtonItem Item in Swift

I am trying to change the text color of the rightBarButtonItem item text and it blue by default . I am trying to change it to black .

My current code for that is:

self.navigationItem.rightBarButtonItem?.tintColor = .black

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This does not change anything and the text color is the same . Added the cancel rightBarButtonItem image that i need to change the text from blue to black. How can i do that enter image description here

>Solution :

Make sure to add your code to your view controller’s viewWillAppear method and call setNeedsStatusBarAppearanceUpdate()

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.navigationBar.tintColor = .black
    setNeedsStatusBarAppearanceUpdate() // don't forget to always call setNeedsStatusBarAppearanceUpdate when changing the button's tintColor
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading