1

I only need to display DELETE and CANCEL button as alert, no alert title or a message, and add action to DELETE button. Tried to modify following code but couldn't succeeded. And additionally, I want to make UIVIEW bit darker when DELETE and CANCEL buttons displayed. 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 ...
OzzY
  • 221
  • 5
  • 16
  • Possible duplicate of [Add Image to UIAlertAction in UIAlertController](http://stackoverflow.com/questions/26347085/add-image-to-uialertaction-in-uialertcontroller) – Michele Giuseppe Fadda Dec 13 '15 at 09:23

2 Answers2

1

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

Community
  • 1
  • 1
Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
0

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,>

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



                                }];

[alert addAction:HDQuality];
Jagveer Singh
  • 2,258
  • 19
  • 34