0

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

Alok
  • 24,880
  • 6
  • 40
  • 67
  • 1
    tintColor only works for button title , Check this question https://stackoverflow.com/questions/31662591/swift-how-to-change-uialertcontrollers-title-color – Rajeev Udayan Dec 06 '17 at 05:24
  • @RajeevUdayan do you have any idea to change text color without using attribute string? – Alok Dec 06 '17 at 05:51

1 Answers1

3

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

Alok
  • 24,880
  • 6
  • 40
  • 67
iVarun
  • 6,496
  • 2
  • 26
  • 34
  • Thanks for your answer, I have changed few syntaxes and updated and accepted your answer. – Alok Dec 06 '17 at 05:47
  • If you have any idea to subclassing of Alertviewcontroller and then change text color without attribute string then please let me know. – Alok Dec 06 '17 at 05:51
  • 1
    @Alok as per apple doc `UIAlertController` is not supporting subclassing. But if you want to use 'UIAlertController' with text color you can create common method in one class and use that method to present `UIAlertController`. – iVarun Dec 06 '17 at 05:55