• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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.运行


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap