最简单iphone程序
HelloWorldViewController:
@interface HelloWorldViewController : UIViewController
@end
@implementation HelloWorldViewController
-(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor lightGrayColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 32.0f)];
NSLog(@"addd label..");
label.text=@"Hello World...";
label.center = contentView.center;
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[contentView addSubview:label];
[label release];
self.view = contentView;
[contentView release];
}
@end
HelloWorldAppDelegate:
@interface HelloWorldAppDelegate : NSObject<UIApplicationDelegate>
@end
@implementation HelloWorldAppDelegate
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
HelloWorldViewController *hwvc;
hwvc = [[HelloWorldViewController alloc] init];
[window addSubview:hwvc.view];
[window makeKeyAndVisible];
return YES;
}
@end
main:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
[pool release];
return retVal;
}