在操作表中显示多个图像

时间:2019-05-17 15:02:52

标签: swift image segue uialertcontroller uialertaction

当前操作表上仅显示一张图像,如何显示两个图像?image of action sheet

@IBAction func areaAdd(_ sender: Any) {
    haptic.prepare()
    haptic.impactOccurred()

    let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

    let areaImage = UIImage(named: "Areas")
    let area = UIAlertAction(title: "Area", style: .default, handler: { action in self.performSegue(withIdentifier: "newArea", sender: self)})
    area.setValue(areaImage?.withRenderingMode(.alwaysTemplate), forKey: "image")
    alert.addAction(area)

    let project = UIAlertAction(title: "Project", style: .default, handler: { action in self.performSegue(withIdentifier: "newProject", sender: self)})
    let projectImage = UIImage(named: "Projects")
    area.setValue(projectImage?.withRenderingMode(.alwaysTemplate), forKey: "image")
    alert.addAction(project)

    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    self.present(alert, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:0)

@IBAction func areaAdd(_ sender: Any) { 
    let alert = UIAlertController(title: nil, message: nil,      preferredStyle: .actionSheet)
    let area = UIAlertAction(title: "Area", style: .default, handler: { action in 
        self.performSegue(withIdentifier: "newArea", sender: self)
    })
    let image = UIImage(named: "myImage")
    area.setValue(image?.withRenderingMode(.alwaysOriginal), forKey: "image")
    alert.addAction(area)
}