swift学习:第一个swift ui程序

最近swift有点火,赶紧跟上学习。于是,个人第一个swift程序诞生了。。。

 

新建项目

Alt text

 

选择ios应用,单视图应用
Alt text

 

随便起个项目名称,语言选择“swift”
Alt text

 

项目建好了,我们这里只需要在AppDelegate.swift文件里加上几行代码就ok
Alt text

 

你会看到下面这个方法。从注释可以看出,应用加载后就会运行这个方法

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    // Override point for customization after application launch.
    return true
}

 

return true之前加上这几行代码,搞定

// 我们的代码
var alert = UIAlertView()
alert.title = "标题"
alert.message = "hello world"
alert.addButtonWithTitle("确定")
alert.show()

 

为方便调试,我们选择ios模拟器,如下图位置,这里选择iphone 4s
Alt text

Alt text

 

运行程序
Alt text

 

如果看到下面界面,恭喜!
Alt text

posted @ 2014-06-10 23:33  程序猿小卡  阅读(3412)  评论(0编辑  收藏  举报