Ios learning Summary (1), ios learning Summary
Original article address
Download and open xcode.
Create a new project, as shown in:
Click Create a new Xcode project, select Application under ios, and click Single View Application to Create our first project. :
After creating a project, we will compile our first ios project.
Find the AppDelegate. m file and add it under "# import" AppDelegate. h:
#import "ViewController.h" |
Then add the following code to the didfinishlaunchingwitexceptions function:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];self.window.rootViewController = [[ViewController alloc]init];[self.window makeKeyAndVisible]; |
The overall structure is shown in:
Next, open ViewController. m and add the following 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(100, 100, 100, 20)];label.text = @"hello world";[self.view addSubview:label]; |
Then add the function:
- (void)clickAction{ NSLog(@"Clicked!");} |
Shows the overall effect:
Click the run icon, as shown in:
The effect after running is as follows:
When you click the red button, Xcode prints the following information:
So far, our first app has been completed.