iOS:Swift介面執行個體1, 簡單介面

來源:互聯網
上載者:User

標籤:style   class   blog   code   tar   ext   

Apple推出了基於Objective-C的新語言Swift. 通過執行個體, 我們可以很好的感受這門新語言

注意事項: 在XCode6_Beta中, 如果有中文, IDE的自動補全功能就會失效, 所以開始調試的時候可以先用英文, 後面再用中文替代.

1. 建立iOS -> Single View Application.

2. 修改AppDelegate.swift檔案

 1 // 2 //  AppDelegate.swift 3 //  UIByCode_Swift_1_HelloWorld 4 // 5 //  Created by yao_yu on 14-6-18. 6 //  Copyright (c) 2014 yao_yu. All rights reserved. 7 // 8  9 import UIKit10 11 @UIApplicationMain12 class AppDelegate: UIResponder, UIApplicationDelegate {13                             14     var window: UIWindow?15 16 17     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {18         self.window = UIWindow(frame: UIScreen.mainScreen().bounds)19         // Override point for customization after application launch.20         let window = self.window!21         window.backgroundColor = UIColor.whiteColor()22         window.makeKeyAndVisible()23         24         let frame = UIScreen.mainScreen().bounds25         let EDGE:CGFloat = 2026         27         var labelHello = UILabel(frame: CGRectMake(EDGE, (frame.height - EDGE)/2, frame.width - EDGE * 2, EDGE))28         labelHello.textAlignment = NSTextAlignment.Center29         labelHello.text = "你好,歡迎來到swift世界!"     //加入中文後,XCode的自動補全功能就不出來了30         window.addSubview(labelHello)31         32         return true33     }34 35     func applicationWillResignActive(application: UIApplication) {36         // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.37         // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.38     }39 40     func applicationDidEnterBackground(application: UIApplication) {41         // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.42         // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.43     }44 45     func applicationWillEnterForeground(application: UIApplication) {46         // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.47     }48 49     func applicationDidBecomeActive(application: UIApplication) {50         // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.51     }52 53     func applicationWillTerminate(application: UIApplication) {54         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.55     }56 57 58 }

3.運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.