1

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

还好警报

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

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

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

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

4

2 回答 2

1

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

于 2019-07-01T22:41:04.167 回答
0

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

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)

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

于 2019-06-28T05:45:21.217 回答