First, create a blank iphone project:
Select the selected icon in the figure, and click next to go to the next step:
Name the project, and then click
Select the location you want to store and create it.
Then create a class to define the interface:
Select a class from the graph to create the class, and click Next.
Name the class and proceed to the next step
Select a path to create
The created Project is
Define the interface in the DemoViewController class: (most of the Code in the class is automatically generated, and only important code is written here)
/* DemoViewController. h */# import <UIKit/UIKit. h> @ interface DemoViewController: UIViewController {// defines a Label, which is used when the container UILabel * helloLabel;} // nonatomic: improves efficiency. The retain: setter method applies the old value of the parameter release, return the new value @ property (nonatomic, retain) UILabel * helloLabel; @ end
/* DemoViewController. m */# import "DemoViewController. h "@ implementation DemoViewController @ synthesize helloLabel; // pre-compiled // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void) viewDidLoad {// CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height) sets the Label display position // CGRectMake (distance from the left border, distance from the top border, Label length, Label height) helloLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 50,300, 60)]; // set helloLabel to display content in the Label. text = @ "Hello World"; // alignment Board (in the middle of a row) helloLabel. textAlignment = UITextAlignmentCenter; // set the font color to Red helloLabel. textColor = [UIColor redColor]; // set the font size to 20 helloLabel. font = [UIFont systemFontOfSize: 20]; // Add the Label to the View [self. view addSubview: helloLabel]; [super viewDidLoad];}
/* AppDelegate. h */# import <UIKit/UIKit. h> @ class DemoViewController; @ interface AppDelegate: UIResponder <response >{// create the DemoViewController class Object DemoViewController * _ iDemoViewController;} @ property (nonatomic, retain) DemoViewController * iDemoViewController; @ property (strong, nonatomic) UIWindow * window; @ end
/* Appdelegate. M */# import "appdelegate. H "# import" demoviewcontroller. H "@ implementation appdelegate // common understanding of the backup variable name: the role is to enable the compiler to use self @ synthesize window = _ window; @ synthesize idemoviewcontroller = _ idemoviewcontroller;-(void) dealloc {self. idemoviewcontroller = nil; [_ window release]; [Super dealloc];}-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {self. window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease]; // override point for customization after application launch. self. window. backgroundcolor = [uicolor whitecolor]; // create a temporary demo demoviewcontroller * demo = [[demoviewcontroller alloc] init]; self. idemoviewcontroller = demo; [demo release]; // release the temporary demo // Add it to window [self. window addsubview: Self. idemoviewcontroller. view]; [self. window makekeyandvisible]; return yes ;}
Then run the project to get the helloworld that we are particularly familiar with and are unfamiliar.