Hello World! Build your first Xamarin iOS App


Take a Look at Your First App

Before we go into the coding part, let’s first take a look at our version of the “Hello World” app. The final deliverable will look like this

Start Coding!

First, launch Xamarin. Once launched, Xamarin displays a welcome dialog. From here, choose “New Solution” to start a new project:

From the New Solution Dialogue, we’ll choose C# > iOS > Unified API > iPhone > Single View Application  template. Let’s give it the  Name Hello_world, and the Solution Name Hello_world:

Next, we’ll open the MainStoryboard.storyboard file by double-clicking on it in the Solution pad:

From the Toolbox (the area on the right), let’s type “Button” into the search bar and drag a Button onto the design surface (the area in the center)

With the Button selected on the design surface, change the Name property in the Identity section of the Property Pad to btn_. Change the Title property to “Click Here”:

Next, grab the handles of the Dragging Controls (the circles around the control) and make the button wider:

Now go to Event tag in button property and write event name in Up Side property. This is the method or event name that has the code that you want to execute when button will press.

Next we’re going to add code to wire up the user interface. Let’s add the code to power the user interface into the Hello_WorldViewController class. Double-click on Hello_WorldViewController.cs in the Solution Pad to open it.

You will find btn_click event

Just write above code into btn_click event to prompt alertview and that’s it.

Let’s save our work, and then build the application by choosing Build=>Build All. If our application compiles, we will get a success message at the top of the IDE:

If there are errors, we can go through the previous steps and correct any mistakes until the application builds successfully.

Finally, let’s test our application in the iOS Simulator. In the top left of the IDE, choose Debug from the first dropdown, and iPhone from second dropdown, and press Start (the round button that resembles a Play button):

This will launch our application inside the iOS Simulator:

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="">