'Background colors of my iOS application doesn't appear on some devices
I am currently developing an iOS application. I have adapted my design to the different Apple devices. However, while testing my app on an iPad Pro 2nd generation, I realized that the design differed on a few points. Here are the differences I found:
In the code, I create custom pop-ups with this code:
func createPopUp(title: String, message: String, preferredStyle: UIAlertController.Style) -> UIAlertController { let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle) alert.setTitlet(font: UIFont.boldSystemFont(ofSize: 17), color: UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1)) alert.setMessage(font: UIFont.systemFont(ofSize: 13), color: UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1)) let subview = alert.view.subviews.first! as UIView let alertContentView = subview.subviews.first! as UIView alertContentView.backgroundColor = UIColor.black // The important line alertContentView.tintColor = UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1) alertContentView.layer.cornerRadius = 15; return alert}
Here is the normal rendering on all my devices:
And the one on the iPad :
- The color of the tab bar changes too:
The normal rendering :
And on the iPad :
- Finally an image intended to blink (by changing the isHidden property):
Photo of the normal render after blinking :
And on the iPad :
There are several common points between these three problems. I think they all concern the background.
I also tested the app on an iPhone 12 which had exactly the same problems. Otherwise on all other devices all work perfectly. Note that the iPhone 12 and the iPad belong to the same owner, so they are connected to the same Apple ID. Maybe the problems are related to settings independent of my application but I have not been able to find out what they are (Accessibility?).
Thank you for your attention!
Solution 1:[1]
You need to find the first subview for 3 times to change the backgroundColor. Here is the code.
func createPopUp(title: String, message: String, preferredStyle: UIAlertController.Style) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
alert.setTitlet(font: UIFont.boldSystemFont(ofSize: 17), color: UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1))
alert.setMessage(font: UIFont.systemFont(ofSize: 13), color: UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1))
if let bgView = alert.view.subviews.first, let groupView = bgView.subviews.first, let contentView = groupView.subviews.first {
contentView.backgroundColor = UIColor.black
}
alert.view.tintColor = UIColor(red: 237.0/255, green: 159.0/255, blue: 94.0/255, alpha: 1)
alert.view.layer.cornerRadius = 16
return alert
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MBT |






