Introduction
Xamarin is a platform to develop cross-platform and multi-platform apps (for example, Windows phone, Android, iOS). In Xamarin platform, the code sharing concept is used. In Xamarin Studio, Visual Studio is also available.
Prerequisites
The steps given below are required to be followed in order to create Toast Notification in Xamarin iOS, using Xamarin Studio.
Step 1
Go To Xamarin Studio.
Click New Solution—> select iOS—>select App--> choose Single View App. Afterwards, click Next.
Step 2
In this step, configure your app. Give the app name (Ex:sample) and Organization Identifier. Afterwards, click Next.
step 3
In this step, give your project name (Ex: Sample) and solution name (Ex: Sample). Give path of your project and click Create.
Step 4
Subsequently, go to the solution and view all the files and sources in your project. Now, select Main.storyboard and double click to open Main.storyboard page.
Step 5
After opening the Main.storyboard, you can design this page, as per your desire.
Step 6
In this step, add the Toast Component in your app.
Now, go to the Solution—>Components—>click "Get More Components".
Step 7
Now, select All Components, search Toast. Choose Toast for iOS.
Step 8
Now, click "Add to App". The component will be added in your app.
Step 9
Now, go to the toolbox window and scroll down to drag and drop the Button.
Next, you need to align the Button, using constraints.
Step 10
Now, go to the properties window. Select the Button and give a name (Ex:btnShowToast).
Step 11
In this step, go to the ViewController.cs page and add the namespace as given below.
ViewController.cs
using ToastIOS;
Step 12
In this step, go to the ViewController.cs page. write the code given below.
ViewController.cs
- namespace XamariniOSToastNotification
- {
- public partial class ViewController: UIViewController {
- protected ViewController(IntPtr handle): base(handle) {
-
- }
- public override void ViewDidLoad() {
- base.ViewDidLoad();
-
- }
- partial void BtnDefault_TouchUpInside(UIButton sender) {
- Toast.MakeText("Hello Xamarin iOS").Show();
- }
- public override void DidReceiveMemoryWarning() {
- base.DidReceiveMemoryWarning();
-
- }
- }
- }
Step 13
Now, go to Run option. Choose "Debug" and from the list of iPhone and iPad simulators, you can choose any simulator and run it.
Output
After a few seconds, the app will start running on your iPhone simulator. You will see your app working successfully.
You can click "Show Toast" button. Toast will be working successfully.
Summary
This was the process of creating the Toast Notification in Xamarin iOS , using Xamarin Studio.