【问题标题】:iOS- UIAlert is only showing "OK" after changing the app icon to an alternate oneiOS- UIAlert 仅在将应用程序图标更改为备用图标后才显示“确定”
【发布时间】:2019-11-09 23:01:57
【问题描述】:

我有一个地方要更改我的应用的应用图标。我可以得到它,以便应用程序图标实际发生变化,但是,应该弹出的警报只显示“OK”。没有文字或图片表明图标已更改。

just okay alert

我想知道视图层次结构是否存在问题?我已经尝试在我的应用程序中的多个位置放置更改功能,并且每次它确实更改图标,但警报仍然是错误的。此外,我找不到打印到控制台的任何错误。

这是我调用图标更改的代码:

UIApplication.shared.setAlternateIconName(ThemeCenter.shared.alternateIconName, completionHandler: nil)

我希望警报告诉用户应用程序图标已更改并显示图标已更改为的图像,如下所示: correct alert 据我所知,这应该是自动发生的。

【问题讨论】:

    标签: ios swift appicon


    【解决方案1】:

    您可以创建警报并向其添加图像视图:

    let showAlert = UIAlertController(title: "Demo Alert", message: nil, preferredStyle: .alert)
    let imageView = UIImageView(frame: CGRect(x: 10, y: 50, width: 250, height: 230))
    imageView.image = image // Your image here...
    showAlert.view.addSubview(imageView)
    let height = NSLayoutConstraint(item: showAlert.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 320)
    let width = NSLayoutConstraint(item: showAlert.view, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 250)
    showAlert.view.addConstraint(height)
    showAlert.view.addConstraint(width)
    showAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
        // your actions here...    
    }))
    self.present(showAlert, animated: true, completion: nil)
    

    您可以根据需要更改尺寸。

    【讨论】:

    • 这个问题是它不会阻止“确定”按钮的显示,因为它是内置在setAlternateIcon 函数中的。但是,弹出我自己的 UIAlert 函数确实可以正常工作。
    【解决方案2】:

    问题最终是在我们的代码中的某个地方,我们扩展了UIAlertController 并覆盖了viewDidLoad 以设置色调。出于某种原因,此覆盖使警报的顶部不显示。取出viewDidLoad 覆盖解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      相关资源
      最近更新 更多