How can I insert images next to text inside a UIActionSheet?

145 Views Asked by At

I was trying to create a UIActionSheet in a Xamarin.ios app, where there is an image and text in each row. Is there a way we could do that?

I've followed the sample provided by Alanc Liu in this link: For "actionSheetAlert", what's after (action) =>.

This is just text, however. How can I replace the string with a combination of image + string?

Screenshot attached to clarify the requirement... Need to add custom images in place of all those smiley faces.

Thank you.

enter image description here

4

There are 4 best solutions below

0
AdamPro13 On BEST ANSWER

This isn't possible with a stock UIAlertController/UIAlertAction. You would need to create a custom view controller to get this functionality.

0
Joshua On

I have used Alert and Picker from dillidon for the basic implementations, the library packs a lot of options for you to choose. For more customisations that can't be supported by the library I tend to create my own controller.

1
khush On

It is possible(without using external library) by overriding one of the properties of alert action. I have achieved the same by following code:

      let actionsheet = UIAlertController.init(title: "Select party", message: nil, preferredStyle: .actionSheet)
        let actn1 = UIAlertAction.init(title: "Party 1", style: .default, handler: { (act) in
            //
        })
        actn1.setValue(UIImage(named: "String"), forKey: "image")
        actionsheet.addAction(actn1)
      self.present(actionsheet, animated: true, completion: nil)

And here you go. Hope this help you.

0
Blazej SLEBODA On

UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with present(_:animated:completion:).

Important: UIActionSheet is deprecated in iOS 8. (Note that UIActionSheetDelegate is also deprecated.) Source