-2

I am unable to change the color of UIBarItem programmatically swift. I want to change the color of this "create" button whether something happens. But nothing changes the color of the button.

Here is an image of the button :

enter image description here

m4thus4n
  • 69
  • 1
  • 6
  • 1
    Please show what you have tried. – rbaldwin May 24 '20 at 07:07
  • Does this answer your question? [Changing font color of UIBarButtonItem](https://stackoverflow.com/questions/44893174/changing-font-color-of-uibarbuttonitem) – rbaldwin May 24 '20 at 07:21
  • I already did what Hasan can said. – m4thus4n May 24 '20 at 07:21
  • 1
    Which is why I asked you post to your code, so we can see what you have already tried, or see if there is a problem with your code. See: How to create a minimal, reproducible example https://stackoverflow.com/help/minimal-reproducible-example – rbaldwin May 24 '20 at 07:23
  • Ok, but I tried the things in page you shared and it didn't work. Can I share a GitHub repository ? – m4thus4n May 24 '20 at 07:25

2 Answers2

0

here is how You can achieve it programatically in viewDidLoad add this

override func viewDidLoad() {
        super.viewDidLoad()


      let butt =   createButton.customView as? UIButton
        butt?.setTitleColor(.green, for: .normal)

        // Do any additional setup after loading the view.
    }

enter image description here

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
-1

Please try tintColor attribute

let rightBarButtonItem = UIBarButtonItem(title: "Text", style: .plain, target: self, action: #selector(objcAction))

rightBarButtonItem.tintColor = UIColor.red

navigationItem.rightBarButtonItem = rightBarButtonItem