Swift - 带有图像的 UIAlertController

Łuk*_*tta 2 iphone ios swift

我有这个代码:

let alert = UIAlertController(title:"title", preferredStyle: UIAlertControllerStyle.alert)
    let saveAction = UIAlertAction(title: "Title", style: .default, handler: nil)

    var imageView = UIImageView(frame: CGRectMake(10, 10, 250, 124))
    imageView.image = zdjecieGlowne
    alert.view.addSubview(imageView)

    alert.addAction(UIAlertAction(title: "Button 1", style: UIAlertActionStyle.default, handler: { alertAction in
        print("1 pressed")
    }))
    alert.addAction(UIAlertAction(title: "Button 2", style: UIAlertActionStyle.cancel, handler: { alertAction in
        print("2 pressed")
    }))
    alert.addAction(UIAlertAction(title: "Button 3", style: UIAlertActionStyle.default, handler: { alertAction in
        print("3 pressed")
    }))
    self.present(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

窗口如下所示:https : //ibb.co/hM5zHH

图片用按钮盖住了我。有谁知道如何修理它?

Roh*_*ana 7

试试这个,它可能会帮助你

    let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
    let action = UIAlertAction(title: "OK", style: .cancel, handler: nil)

    //Add imageview to alert
    let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
    imgViewTitle.image = UIImage(named:"image.png")
    alert.view.addSubview(imgViewTitle)

    alert.addAction(action)
    self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)