May Phyu
May Phyu

Reputation: 905

Alertbox and Action Sheet in swift 3

I would like to choose the package type when I press on button.
There are three types of package.

1. Package A
2. Package B
3. Package C

enter image description here

I have confused of how to implement this process. I don't know exactly it should be alert box or action sheet?
I'm not clearly understood this. Above image is action sheet, isn't it?
But, I found that action sheet style has been deprecated in iOS 8 and later. So, I could not use this?
Could you please explain me difference between Action sheet and Alert box in swift.? Thank you.

Upvotes: 0

Views: 1575

Answers (1)

deepak joshi
deepak joshi

Reputation: 155

Action sheets and Alert can be created with UIAlertController : To create an Action Sheet you have to create an instance of UIAlertController and Adding actions to it : -

let actionSheet = UIAlertController(title: "Choose Package Type", message: nil , preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Package A", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Package B", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Package C", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel , handler: {
                (action: UIAlertAction) -> Void in
                actionSheet.dismiss(animated: true, completion: nil)
            }))
 present( actionSheet , animated:  true , completion:  nil)

You can replace the handler and replace with #selector as per your task .

Upvotes: 1

Related Questions