3

I want to style the look of my AlertController in the app using appearance. It works well for the background and the buttons, but no matter what I try, the labels for title and message always stay black.

Here is what I am doing:

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .orange
UIVisualEffectView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).effect = UIBlurEffect(style: .dark)
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).textColor = .white

This is the result I get:

enter image description here

Any ideas, how I can set the color of title and message, or why changing the appearance of UILabel does not work in this case?

Community
  • 1
  • 1
gebirgsbärbel
  • 2,327
  • 1
  • 22
  • 38
  • Possible duplicate of [UIAlertController custom font, size, color](https://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color) – Fantini Dec 13 '18 at 21:59

1 Answers1

0

The simplest approach is: don't.

There is absolutely no need for you to feel confined to the use of UIAlertController and its simple default view appearance and content. It is nothing but a presented view controller, after all. That means that you can write your own presented view controller that looks and behaves almost like a UIAlertController and its view, except now you are in total charge of its content!

It is far better, easier, and more reliable to write your own alert-like presented view controller than to try to hack into UIAlertController's view; the former is totally legal, while the latter, aside from being unreliable, can get your app barred from the App Store.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    I know, I can do that. Stupid question, but changing the appearance property of views should be legal, shouldn't it? I thought only usage of private API is forbidden, or do you think even the changes above could be considered a reason to ban the app by apple? – gebirgsbärbel Dec 15 '18 at 06:30
  • I can’t speak for Apple. The fact that you are having trouble doing this shows that you are not supposed to do it. You are fighting the framework so the framework is fighting back. There is an easy way. Why throw yourself against a wall when the door is open? – matt Dec 15 '18 at 06:41