Search code examples
iosuialertcontrollertintcolor

Change Alertview UIAlertController Buttons and Title color in iOS


I wanted to change my alert view title and button color as per my App theme and for this, i have found the many solutions as below:

alertController.view.tintColor = UIColor.red

But above code is changing only button title color not the Alert title.

Testing on iOS 11 using Xcode 9.1


Solution

  • Use below code to change Alert title:

     alertController.setValue(NSAttributedString(string: "test", attributes: [NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor : UIColor.red]), forKey: "attributedTitle")
    

    enter image description here