iOS Learning Summary (1)--Create your first iOS project

Source: Internet
Author: User

Original address

Download and open Xcode.

Then create a new project, as shown in:

Click Create a new Xcode project, then select Application under iOS and click Single View application to build our first project. :

After the project is created, let's write our first iOS project.

Locate the APPDELEGATE.M file, and first add the following under "#import " AppDelegate.h "":

#import "ViewController.h"

Then in the Didfinishlaunchingwithoptions function, add the following code:

Self.window = [[UIWindow alloc] Initwithframe:[[uiscreen mainscreen] Bounds]];self.window.rootviewcontroller = [[ Viewcontroller Alloc]init]; [Self.window makekeyandvisible];


The whole looks as follows:

Next, we open viewcontroller.m and add in the Viewdidload function:

 UIButton *BTN = [[UIButton alloc]initwithframe:cgrectmake (0, 0, 100, 100)]; [Btn Setbackgroundcolor:[uicolor Redcolor]; [Btn addtarget:self Action: @selector (ClickAction) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN]; UILabel *label = [[UILabel alloc]initwithframe:cgrectmake (+, +, +)];label.text = @ "Hello world";
  [Self.view Addsubview:label]; 

Then add the function:

-(void) clickaction{    NSLog (@ "clicked!");}

The overall effect is as follows:


Then click on the Run icon as shown in:

The post-operation effect is as follows:

When we click on the red button, Xcode prints the following message:

So far, our first app is done.

iOS Learning Summary (1)--Create your first iOS project

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.