码迷,mamicode.com
首页 > 移动开发 > 详细

iOS:Swift界面实例1, 简单界面

时间:2014-06-19 07:23:21      阅读:436      评论:0      收藏:0      [点我收藏+]

标签: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 UIKit
10 
11 @UIApplicationMain
12 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().bounds
25         let EDGE:CGFloat = 20
26         
27         var labelHello = UILabel(frame: CGRectMake(EDGE, (frame.height - EDGE)/2, frame.width - EDGE * 2, EDGE))
28         labelHello.textAlignment = NSTextAlignment.Center
29         labelHello.text = "你好,欢迎来到swift世界!"     //加入中文后,XCode的自动补全功能就不出来了
30         window.addSubview(labelHello)
31         
32         return true
33     }
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.运行

iOS:Swift界面实例1, 简单界面,布布扣,bubuko.com

iOS:Swift界面实例1, 简单界面

标签:style   class   blog   code   tar   ext   

原文地址:http://www.cnblogs.com/yaoyu126/p/3794029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!