iOS13 UIAlertController with custom view & preferredStyle as actionsheet grayscale all colors

天大地大妈咪最大 提交于 2020-05-16 03:39:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!