How to create Action sheets using Xamarin iOS.

Xamarin.iOS
img_xamarin

In this tutorial we are going to see some basic controls that are needed to develop a regular application like:

  • ActionSheet
  • Buttons
  • Label
  • ImageView

ActionSheet: Action sheets consist of a really convenient and fast way to display a bunch of options that the user should select from, and it is widely used in great number of applications. Its disadvantage though is that it adopts the iOS’s look and feel without being able to be graphically modified; therefore it might not fit to applications with customized GUI.

We are going to see a small tutorial that display ActionSheet when press on certain buttons. When we complete our tutorial it will look like this:

4a

4b

Select Unified API and iPhone , we are going to need only 1 screen so we are taking Single View Application. Give name of application “ActionSheet_Demo”.

Let’s begin: Go on New Solution and create new iOS solution.

c

Select Unified API and iPhone , we are going to need only 1 screen so we are taking Single View Application. Give name of application “ActionSheet_Demo”.

4c

Now we get a blank storyboard where we take 2 buttons for using storyboard. When you clink on these buttons it invokes a ActionSheet controller.

4d

Now go and declare name in identity to access button click event or touch up inside. Here we give btn_normal for Simple Action Sheet and btn_option for Delete Confirmation Action Sheet.

In ActionSheet_DemoViewController file declare UIActionSheet object.

Now go in ViewDidLoad method and write code below

We’re almost done here, now just call the object ob UIActionSheet and you get ActionSheet.
Find TouchUpInside method of buttons that we were created earlier and call actionsheet method with the help of object.

Write the code below to get it done:

We’ve created UIActionSheet object and used with button actions but what about using this actionsheet buttons???

For that, we’ve to use

Add these lines before you call the methods of ActionSheet ShowInView in button action event.
And that’s it, you get index number of button in your Application Output. Just run and check it.

4a

If you like this tutorial then you can download full copy of the code from github

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">