IOS成長之路-第一個Hello World項目

來源:互聯網
上載者:User

先建立一個空白的iphone項目:

選圖中已經選中的表徵圖,然後點擊next,進入下一步:

為這個項目命名,然後next

選擇想要儲存的位置,然後建立就ok了

然後建立類來定義介面:

選擇圖中選中的類進行建立,點擊下一步

為類命名,進行下一步

選取路徑進行建立

建立好的項目為

在DemoViewController類中定義介面:(類中大多代碼為自動產生,在此唯寫重要代碼)

/*DemoViewController.h*/#import <UIKit/UIKit.h>@interface DemoViewController : UIViewController{    //定義一個Label,用來當容器    UILabel * helloLabel;}//nonatomic:提高效率,retain:setter方法對參數release舊值,返回新值@property(nonatomic,retain)UILabel* helloLabel;@end

/*DemoViewController.m*/#import "DemoViewController.h"@implementation DemoViewController@synthesize helloLabel;//先行編譯// 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)設定Label顯示的位置    //CGRectMake(和左邊邊框的距離,和上邊邊框的距離,Label的長度,Label的高度)    helloLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 300, 60)];        //設定Label中要顯示的內容    helloLabel.text = @"Hello World";    //對齊   局中(一行的中間)    helloLabel.textAlignment = UITextAlignmentCenter;    //設定字型顏色為紅色    helloLabel.textColor = [UIColor redColor];    //設定字型字型大小為20    helloLabel.font = [UIFont systemFontOfSize:20];    //把Label添加到View中    [self.view addSubview:helloLabel];    [super viewDidLoad];}

/*AppDelegate.h*/#import <UIKit/UIKit.h>@class DemoViewController;@interface AppDelegate : UIResponder <UIApplicationDelegate>{    //建立DemoViewController類的對象    DemoViewController* _iDemoViewController;}@property (nonatomic,retain)DemoViewController* iDemoViewController;@property (strong, nonatomic)UIWindow *window;@end

/*AppDelegate.m*/#import "AppDelegate.h"#import "DemoViewController.h"@implementation AppDelegate//備份變數名   通俗理解:作用就是讓編寫者學會運用self@synthesize window = _window;@synthesize iDemoViewController = _iDemoViewController;- (void)dealloc{        self.iDemoViewController = nil;    [_window release];    [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];            //建立出一個臨時的Demo    DemoViewController *demo = [[DemoViewController alloc]init];        self.iDemoViewController = demo;    [demo release];//釋放臨時Demo    //添加到window中    [self.window addSubview:self.iDemoViewController.view];            [self.window makeKeyAndVisible];    return YES;}

然後運行項目就可以得到我們特別熟悉而又陌生的HelloWorld了

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.