问题
I have an app I built in Xcode 8 for iOS 10 originally. I recently upgraded to Xcode 9 and have been making fixes to my app for the iPhone X and iOS 11. One issue I'm having a lot of trouble with is how to make the whole screen (including the area by the notch) dim when presenting an alert. See image:
I am presenting the alert on the "Connect" View Controller (what you see below). I've done nothing to manipulate the root View of this View Controller. I have "checked" "Safe Area Relative Margins" and "Safe Area Layout Guide" in the Storyboard for this root view. (I've also tried every other permutation of checking / not checking these boxes, and nothing makes a difference.)
Interestingly, when I run this build on my own iPhone 6, the status bar is also not dimmed (although it's a lot less noticeable since the status bar is a lot smaller pre-iPhone X). This issue definitely began occurring in Xcode 9 because my current version on the App Store (built with Xcode 8) dims the whole screen on alerts.
Does anyone have any ideas on how to solve this issue? Let me know if you need other information.
回答1:
Update info.plist with
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Use adding subview to the UIWindow
as -
UIApplication.shared.statusBarStyle = .lightContent//for white color
let statusBarBgView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIApplication.shared.statusBarFrame.height))
statusBarBgView.backgroundColor = UIColor.red//status bar color
window?.rootViewController = MYViewController//Entry point
window?.rootViewController?.view.addSubview(statusBarBgView)//Adding to window
Result with alert popup ->
Result with background apps listing ->
来源:https://stackoverflow.com/questions/47860333/alerts-on-iphone-x-shows-different-color-with-uialertcontroller-popup