问题
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:
and on iOS 13:
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?
回答1:
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
来源:https://stackoverflow.com/questions/56955800/ios13-uialertcontroller-with-custom-view-preferredstyle-as-actionsheet-graysca