Ray's playground

 

Building Your First Project(Chapter 2 of The iPhone™ Developer’s Cookbook)

 1 #import <UIKit/UIKit.h>
 2 
 3 @interface HelloWorldViewController : UIViewController
 4 @end
 5 
 6 @implementation HelloWorldViewController
 7 - (void)loadView
 8 {
 9     UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
10     contentView.backgroundColor = [UIColor lightGrayColor];
11     
12     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f0.0f320.0f30.0f)];
13     label.text = @"Hello world";
14     label.center = contentView.center;
15     label.textAlignment = UITextAlignmentCenter;
16     label.backgroundColor = [UIColor clearColor];
17     
18     [contentView addSubview:label];
19     [label release];
20     
21     self.view = contentView;
22     [contentView release];
23 }
24 @end
25 
26 @interface HelloWorldAppDelegate : NSObject<UIApplicationDelegate>
27 @end
28 
29 @implementation HelloWorldAppDelegate
30 - (void)applicationDidFinishLaunching:(UIApplication *)application
31 {
32     UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
33     
34     HelloWorldViewController *hwvc;
35     hwvc = [[HelloWorldViewController alloc] init];
36     [window    addSubview:hwvc.view];
37     [window makeKeyAndVisible];
38 }
39 @end
40 
41 
42 int main(int argc, char *argv[]) {
43     
44     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
45     int retVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
46     [pool release];
47     return retVal;
48 }
49 

 

posted on 2010-12-22 18:45  Ray Z  阅读(3735)  评论(0编辑  收藏  举报

导航