////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>//View Controller Objects@interfaceHelloworldviewcontroller:uiviewcontroller@end@implementationHelloworldviewcontroller-(void) loadview{//Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; //Create a Label objectUILabel *label = [[UILabel alloc]initwithframe:cgrectmake (0.0,0.0,320.0,30.0)]; Label.text=@"Hello World"; Label.center= Contentview.center;//Center VerticallyLabel.textalignment = Uitextalignmentcenter;//Center HorizontallyLabel.backgroundcolor =[Uicolor Clearcolor]; Label.textcolor=[Uicolor Redcolor]; //add a label to a view[Contentview Addsubview:label];}@end//Delegate Object@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Helloworldviewcontroller*Viewcontroller;//window must be declared as a property, declared as a local variable, cannot draw a view, display as a black screen//The official Apple document also declares Viewcontroller as a property.@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizeViewcontroller;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Self.viewcontroller=[[Helloworldviewcontroller alloc]init]; Self.window.rootViewController=Self.viewcontroller; [Self.window makekeyandvisible];}@end//Program EntryintMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}
iOS Edition Hello,world version 2