Swift3 如何在Swift 3中将图像添加到UIAlertbox中?

Swift3 如何在Swift 3中将图像添加到UIAlertbox中?,swift3,uiimageview,uialertview,uialertcontroller,Swift3,Uiimageview,Uialertview,Uialertcontroller,我想在UIAlertbox中添加图像,所以我添加了以下代码 当我运行应用程序时,只会显示一个图像。这个怎么了 有人能帮帮我吗?试试这段代码,它在swift3中工作 let alertMessage = UIAlertController(title: "Gender", message: "", preferredStyle: .alert) let image = UIImage(named: "blanckstar") let action = UIAlertAc

我想在UIAlertbox中添加图像,所以我添加了以下代码

当我运行应用程序时,只会显示一个图像。这个怎么了

有人能帮帮我吗?

试试这段代码,它在swift3中工作

    let alertMessage = UIAlertController(title: "Gender", message: "", preferredStyle: .alert)

    let image = UIImage(named: "blanckstar")
    let action = UIAlertAction(title: "Male", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Male")

    }
    action.setValue(image, forKey: "image")

    let image2 = UIImage(named: "blanckstar")
    let action2 = UIAlertAction(title: "Female", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Female")

    }

    action2.setValue(image2, forKey: "image")

    alertMessage.addAction(action)
    alertMessage.addAction(action2)

    self.present(alertMessage, animated: true, completion: nil)
快乐涂层:-)

要更改图像大小,您可以尝试使用fontAwesome,只需安装pod即可

pod'FontAwesome.swift'和import FontAwesome\u swift

这是代码……

    let alertMessage = UIAlertController(title: "Gender", message: "", preferredStyle: .alert)

    let image = UIImage.fontAwesomeIcon(name: .male, textColor: UIColor.black, size: CGSize(width: 50, height: 50))
    let action = UIAlertAction(title: "Male", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Male")

    }
    action.setValue(image, forKey: "image")

    let image2 = UIImage.fontAwesomeIcon(name: .female, textColor: UIColor.black, size: CGSize(width: 50, height: 50))
    let action2 = UIAlertAction(title: "Female", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Female")

    }

    action2.setValue(image2, forKey: "image")

    alertMessage.addAction(action)
    alertMessage.addAction(action2)

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

试试这段代码,它在swift3中工作

    let alertMessage = UIAlertController(title: "Gender", message: "", preferredStyle: .alert)

    let image = UIImage(named: "blanckstar")
    let action = UIAlertAction(title: "Male", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Male")

    }
    action.setValue(image, forKey: "image")

    let image2 = UIImage(named: "blanckstar")
    let action2 = UIAlertAction(title: "Female", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Female")

    }

    action2.setValue(image2, forKey: "image")

    alertMessage.addAction(action)
    alertMessage.addAction(action2)

    self.present(alertMessage, animated: true, completion: nil)
快乐涂层:-)

要更改图像大小,您可以尝试使用fontAwesome,只需安装pod即可

pod'FontAwesome.swift'和import FontAwesome\u swift

这是代码……

    let alertMessage = UIAlertController(title: "Gender", message: "", preferredStyle: .alert)

    let image = UIImage.fontAwesomeIcon(name: .male, textColor: UIColor.black, size: CGSize(width: 50, height: 50))
    let action = UIAlertAction(title: "Male", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Male")

    }
    action.setValue(image, forKey: "image")

    let image2 = UIImage.fontAwesomeIcon(name: .female, textColor: UIColor.black, size: CGSize(width: 50, height: 50))
    let action2 = UIAlertAction(title: "Female", style: .default)
    {
        UIAlertAction in
        // exit(0)
        debugPrint("Press Female")

    }

    action2.setValue(image2, forKey: "image")

    alertMessage.addAction(action)
    alertMessage.addAction(action2)

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

你好,兄弟@seggy,你的代码工作!!非常感谢兄弟。但是,我想编辑图像大小。所以,我添加了这些代码。让femaleimgView=UIImageView(帧:CGRect(x:10,y:10,宽度:30,高度:30))和femaleimgView.image=femaleimage。动作1.设置值(femaleimgView,forKey:“图像”)。当我添加此代码时,出现错误:(这对你有用吗?是的,兄弟。谢谢:)你好@seggy,兄弟,你能帮我查看我的链接吗?我有点问题,对不起,伙计,我太胖了。。。您使用的是自动布局还是自动调整大小?您好,兄弟@seggy,您的代码工作!!非常感谢兄弟。但是,我想编辑图像大小。所以,我添加了这些代码。让femaleimgView=UIImageView(帧:CGRect(x:10,y:10,宽度:30,高度:30))和femaleimgView.image=femaleimage。动作1.设置值(femaleimgView,forKey:“图像”)。当我添加此代码时,出现错误:(这对你有用吗?是的,兄弟。谢谢:)你好@seggy,兄弟,你能帮我查看我的链接吗?我有点问题,对不起,伙计,我太胖了。。。您使用的是自动布局还是自动调整大小?