Xamarin. ios -- First APP, xamarin. iosapp

Source: Internet
Author: User

Xamarin. ios -- First APP, xamarin. iosapp

Environment: MAC + Xamarin Studio

Let's talk about installation first. The most common method is to go to the Xamarin official website, register an account, enter the information, and download and install it. However, in the network environment of tianchao, when downloading Dongdong from the android module, the download will always fail, but you cannot skip it. I once went to download it for one night, hoping to comfort myself with a better network quality at night. As a result, when I arrived the next morning, I found that the download failed. In order to avoid new people into the trap again, and you talk about another download method, search xamarin studio download xml with Google, enter the website https://static.xamarin.com/installer_assets/v3/Mac/Universal/InstallationManifest.xml, find the link, batch download, install. The following screenshot explains:

The layout of the created Project is storyboard by default. We can see a piece of white, which is displayed on the Main. storyboard. Why is the layout displayed on the Main. storyboard displayed? This is related to the settings in Info. plist. The specific position is marked by the red line in.

Okay. Next, Open Main. the storyboard file, as shown in the left figure below. The arrow in the red rectangle box can be understood as the starting point. The arrow points to a ViewController, and the APP uses the ViewController as the first page displayed after the LaunchScreen, there are two ways to set it: simple and crude, drag it directly, and set properties. Select ViewController and select the properties in the red box on the right.

Next, we will implement a simple function. click the Button to change the background color of the View. Drag a Button to View, double-click the Button, and press enter to determine the writing position of the event to create the event method. Is it similar to winform.

    public partial class ViewController : UIViewController    {        bool isWhite = true;        protected ViewController(IntPtr handle) : base(handle)        {        }        partial void UIButton10_TouchUpInside(UIButton sender)        {            if (isWhite)            {                this.View.BackgroundColor = UIColor.Red;                isWhite = false;            }            else            {                 this.View.BackgroundColor = UIColor.White;                isWhite = true;            }        }    }

Of course, you can also tear an event. On the storyboard, assign a value to the Name of the Button in the Button attribute.

public partial class ViewController : UIViewController    {        bool isWhite = true;        protected ViewController(IntPtr handle) : base(handle)        {                  }        public override void ViewDidLoad()        {            base.ViewDidLoad();
button.TouchDown+=(o,s)=> { if (isWhite) { this.View.BackgroundColor = UIColor.Red; isWhite = false; } else { this.View.BackgroundColor = UIColor.White; isWhite = true; } }; } }

Some people may ask how a storyboard is associated with the. CS file? The answer is also in storyboard. The class option in the ViewController attribute is the key to association with the. CS file.

I also asked, "My button only sets the name of the Button in the storyboard. How can I use it directly in the class file? The answer is in. designer. cs under the class file.

  

 

In this way, we have completed the first APP.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.