2

I'm not exactly sure if it's a bug or a feature, but this code:

let sheet = UIAlertController(customView: awesomeView, preferredStyle: .actionSheet)
....
present(sheet, animated: true, completion: nil)

in pre-iOS 13 gives me this result:

enter image description here

and on iOS 13:

enter image description here

I.e. all the customview's elements have been grayscale. I've tried to play with Tint/Text/Background/... colors of the buttons / label - in iOS 13 is does no effect at all. In older versions - UI is changing.

The goal: to avoid the grayscale-effect.

Also, I've noticed that if I change the preferredStyle to .alert(instead of .actionSheet) - I get my colors back, but I'd prefer to keep the layout as it is today.

OS: iOS 13 & Xcode 11 - beta 3 (also had exactly the same problem with beta 1 and 2)

The only workaround I see so far is to stay away from UIAlertController, but maybe there's any better way to fix it?

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
  • 1
    UIAlertController has never supported adding subviews or any other customizations. If you want such changes, don't use UIAlertController. Use or write a custom action sheet as needed. – rmaddy Jul 09 '19 at 15:38
  • 1
    There is no API to init UIAlertController with a customView. Is this a third party library you added? – Jordan H Jul 11 '19 at 16:54
  • 1
    @JordanH huh, that's pretty embarrassing :) Yeah, I have written an extensions years ago and following suggestions from https://stackoverflow.com/questions/32790207/uialertcontroller-add-custom-views-to-actionsheet and totally forgot about it. Either way, the question-wise - I've just dropped UIAlertController and hacked up an animated sheet from the regular UIViewController. – Konstantin Loginov Jul 11 '19 at 17:03

1 Answers1

2

The way you were adding the custom view to the alert controller doesn‘t work anymore. You need to set the view via keypaths instead: https://github.com/chrs1885/SheetyColors/blob/be0de5cdda9b72f5655a3fdd5e40d4bc54a8c090/SheetyColors/Classes/Common/Views/Extensions/UIAlertController%2BcustomView.swift

chrs1885
  • 21
  • 2