简体   繁体   English

如何在UIAlertController中显示图像

[英]How to display image in a UIAlertController

I only need to display DELETE and CANCEL button as alert, no alert title or a message, and add action to DELETE button. 我只需要显示DELETE和CANCEL按钮作为警报,没有警报标题或消息,然后将操作添加到DELETE按钮即可。 Tried to modify following code but couldn't succeeded. 试图修改以下代码,但未能成功。 And additionally, I want to make UIVIEW bit darker when DELETE and CANCEL buttons displayed. 另外,当显示DELETE和CANCEL按钮时,我想使UIVIEW变暗。 What is the best way to do this ? 做这个的最好方式是什么 ?

DELETE and CANCEL Button 删除和取消按钮

 let refreshAlert = UIAlertController(title: "Alert", message: "Are you sure ?", preferredStyle: UIAlertControllerStyle.Alert)

    var imageView = UIImageView(frame: CGRectMake(220, 10, 40, 40))
    let yourImage = UIImage(named: "delete")
    imageView.image = yourImage

    refreshAlert.view.addSubview(imageView)

    refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in ...

This code will help: 此代码将帮助:

let image = UIImage(named: "myImage")
var action = UIAlertAction(title: "title", style: .Default, handler: nil)
action.setValue(image, forKey: "image")
alert.addAction(action)

From: Add Image to UIAlertAction in UIAlertController 来自: 将图像添加到UIAlertController中的UIAlertAction

Some emojis have images , you can use these, This can be helpful for you if your image have standard emoji. 有些表情符号包含图片,您可以使用它们,如果您的图片具有标准表情符号,这可能对您有所帮助。 please check LOCK emoji in example,> 请检查示例中的LOCK表情符号,>

UIAlertAction* HDQuality = [UIAlertAction
                                actionWithTitle:@"🔒 lockk Action"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {
                                    [alert dismissViewControllerAnimated:YES completion:nil];



                                }];

[alert addAction:HDQuality];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM