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

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

时间: 2024-07-30 10:17:58

iOS:Swift界面实例1, 简单界面的相关文章

Swift 写一个简单界面(实战-新手)

原文链接 在这篇博文中你可以看到那些内容呢, 首先这是一个用tableView纯代码Swift写的简单界面, 你可以看到下面这些 - 使用Alamofire 进行网络请求 - 使用MJExtension 进行字典转模型 - 使用HanekeSwift 进行图片的赋值 - 如何写一个模型(M) - 如何自定义一个UITableViewCell Alamofire 简单网络请求 func XTNetworkReq(url: String){ print("SUMMER_TEST_1") A

iOS Swift WisdomHUD 提示界面框架

iOS Swift WisdomHUD 提示界面框架  Framework Use profile(应用简介) 一:WisdomHUD简介 今天给大家介绍一款iOS的界面显示器:WisdomHUD,WisdomHUD是Swift 4.2编写的framework,支持iOS8.0及以上使用,并且完成兼容OC项目的调用, 使用方便,支持动态属性可设置. 二:WisdomHUD集成 1. pod集成:pod  'WisdomHUD' 2. github链接地址:https://github.com/t

iOS手势 规避同一界面上不同子界面同时响应多个手势

最近在项目中遇到这样一个有关iOS手势的问题,首先需求描述如下:“在一个CollectionView中,要求长按不同的cell,产生一个cell的snapshot,此时可拖拽这个snapshot再进行后续的操作(如拖到view的某个位置出发一个事件)”.需求本身并不复杂,但要求每次只能有一个cell响应长按手势,不允许同时有两个或以上的cell响应长按手势. 我们知道UIGestureRecognizer有很多回调和方法可以兼容同一个View上的多种手势,网上相关的教程也很多,比如: http:

iOS开发项目篇—54"设置"界面的搭建

iOS开发项目篇—54"设置"界面的搭建 一.实现 新建一个设置控制器,当点击“我”控制器导航栏“设置”按钮时,即跳转到该界面 1.在“我”控制器中对导航栏“设置按钮”的处理 1 // 2 // YYProfileViewController.m 3 // 4 5 #import "YYProfileViewController.h" 6 #import "YYCommonGroup.h" 7 #import "YYCommonItem

iOS开发项目篇—53"我"界面的搭建

iOS开发项目篇—53"我"界面的搭建 一.简单说明 由于“我”这个界面和发现控制器的界面在本质上是一样的,所以,在这里可以拷贝以快速的完成“我”这个控制器界面的搭建. 全部拷贝,粘贴之后,简单的调整就可以了. 实现的代码如下: YYProfileViewController.m文件 1 // 2 // YYProfileViewController.m 3 // 4 5 #import "YYProfileViewController.h" 6 #import &

iOS开发项目篇—49“发现”界面完善

iOS开发项目篇—49“发现”界面完善 一.简单说明 已经完成的效果:----->目标效果        需要完善的地方: (1)子标题和标题显示在同一行上. 修改样式:UITableViewCellStyleSubtitle--->UITableViewCellStyleValue1 1 //初始化类方法 2 +(instancetype)cellWithTablView:(UITableView *)tableView 3 { 4 static NSString *ID=@"ID

【Unity】UGUI系列教程——拼接一个简单界面

0.简介: 在目前的游戏市场上,手游依然是市场上的主力军,而只有快速上线,玩法系统完善的游戏才能在国内市场中占据份额.而在手游开发过程中,搭建UI系统是非常基本且重要的技能,极端的说如果对Unity的UI系统熟悉,就可以去游戏公司上班了 :)(笑~). 但是就像蛋炒饭,最简单的事要做好也是非常困难的.UI这块的变动也经常是整个游戏最频繁的一块,如果没有一个合理的设计思路,和管理方案,后期将会陷入无止境的调试优化之中. 万丈高楼平地起,现在让我们开始从Unity中的UGUI系统进行讲解. 1.创建

iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(一)

iOS开发UI篇-以微博界面为例使用纯代码自定义cell程序编码全过程(一) 一.storyboard的处理 直接让控制器继承uitableview controller,然后在storyboard中把继承自uiviewcontroller的控制器干掉,重新拖一个tableview controller,和主控制器进行连线. 项目结构和plist文件 二.程序逻辑业务的处理 第一步,把配图和plist中拿到项目中,加载plist数据(非png的图片放到spooding files中) 第二步,字

iOS: 学习笔记, 添加一个带界面约束的控制器

1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad 1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 //创建标题 5 UILabel *header = [[UILabel alloc] init]; 6 header.text = @"欢迎来到我的世界!"; 7 header.textAlignment = NSTextAlignmentCenter