gpt4 book ai didi

swift - 如何调整显示在警报 Controller 上的图像的大小?

转载 作者:行者123 更新时间:2023-11-28 13:50:26 27 4
gpt4 key购买 nike

我有一个按钮,每次按下它都会显示一个显示图像的 UIAlertController。我的问题是图像比警报 Controller 框大,我丢失了一部分。

如何调整图像大小以缩小它?

我的 Swift 3 代码:

func buttonAction(sender: UIButton!) {

let alertMessage = UIAlertController(title: "Alérgeno:", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)

action.setValue(UIImage(named: "zale1")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")
alertMessage .addAction(action)
self.present(alertMessage, animated: true, completion: nil)

}

这是结果

error AlertController

最佳答案

你正在使用 UIAlertViewController 所以定义一个 imageview 并直接将这个 imageview 分配给 uialertviewcontroller 的 View

 @IBAction func buttonAction(sender: UIButton!) {

let alertMessage = UIAlertController(title: "Alérgeno:", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
let imageView = UIImageView(frame: CGRect(x: 10, y: 10, width: 40, height: 40))
let image = UIImage(named: "your image name");
imageView.image = image
alertMessage.view.addSubview(imageView)

alertMessage .addAction(action)
self.present(alertMessage, animated: true, completion: nil)

}

关于swift - 如何调整显示在警报 Controller 上的图像的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54706065/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com