我的iOS应用程序的背景颜色不出现在某些设备上

发布于 2025-01-22 11:00:19 字数 2153 浏览 2 评论 0原文

我目前正在开发iOS应用程序。 我将设计调整为不同的Apple设备。 但是,在对iPad Pro第二代测试我的应用程序时,我意识到该设计在几点方面有所不同。 这是我发现的区别:

  • 在代码中,我使用此代码创建自定义弹出窗口:

      func createPopup(标题:字符串,消息:字符串,preferredstyle:uialertController.style) - > uialertController {
      让警报= uialertController(标题:标题,消息:消息,preferredstyle:preferredstyle)
    
      arter.settitlet(字体:uifont.boldsystemfont(ofSize:17),颜色:uicolor(红色:237.0/255,绿色:159.0/255,蓝色:94.0/255,alpha:1))
      alter.setMessage(字体:uifont.systemfont(ofSize:13),颜色:uicolor(红色:237.0/255,绿色:159.0/255,蓝色:94.0/255,alpha:1))
    
      令subview = alert.view.subviews.first!作为uiview
      令AlertContentView = subview.subviews.first!作为uiview
      alertcontentview.backgroundColor = uicolor.black //重要行
      AlertContentView.TintColor = Uicolor(红色:237.0/255,绿色:159.0/255,蓝色:94.0/255,Alpha:1)
      AlertContentView.Layer.CornerRadius = 15;
    
      返回警报
     

    }

这是我所有设备上的普通渲染:

“

和iPad上的一个:

  • ​也更改:

正常渲染:

“

和在iPad上:

”修改后的渲染“

  • 最后一个旨在闪烁的图像(通过更改Ishidden属性):

闪烁后正常渲染的照片:

和iPad上的:

”修改后的渲染

这三个问题之间有几个共同点。我认为他们都关心背景。

我还在iPhone 12上测试了该应用程序,该应用程序遇到了完全相同的问题。否则,在所有其他设备上都可以很好地工作。 请注意,iPhone 12和iPad属于同一所有者,因此它们连接到同一Apple ID。也许问题与独立于我的应用程序的设置有关,但我无法找出它们是什么(可访问性?)。

感谢您的关注!

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:

Normal rendering

And the one on the iPad :

Modified rendering

  • The color of the tab bar changes too:

The normal rendering :

Normal rendering

And on the iPad :

Modified rendering

  • Finally an image intended to blink (by changing the isHidden property):

Photo of the normal render after blinking :

Normal rendering

And on the iPad :

Modified rendering

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2025-01-29 11:00:20

您需要查找3次的第一个子视图才能更改backgroundColor。这是代码。

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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文