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