您的位置:首页 > 移动开发

Xcode快速入门-2-第一个APP - Hello World

2015-10-23 14:14 495 查看
1、建立专案:

a.选择第二项:Create a new Xcode project

b.iOS中选择Application中的Single View Application

c.product name:APP名称

organization name:组织名称

organization identifier:网域名

bundle identifier:APP识别码(自动产生)

language:开发语言=>选SWIFT

devices:iPhone

Use Core Data:不勾选

下一步,选择存储代码文件夹

2、在左侧档案检阅器(Interface Builder Document)选择Main.storyboard,将「Use Size Classes」前面的勾取消,这时Xcode会提示选择一个目标,选择iPhone。

3、在视图上加上按钮

a.右下方的工具区块中,会列出元件库(Object Library),把按键拖拉到故事板中。

b.修改按钮名称为-Hello World

4、加上代码

在Project Navigator中找到ViewController.swift,在原有的

super.viewDidload()

override func didReceiveMemoryWarining()

这两个方法下面加上

@IBAction func showMessage(){
let alertController = UIAlertController(title: "Welcome to My First App", message: "Hello Wolrd", preferredStyle : UIAlertControllerStyle.Alert)

alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:  nil))

self.presentViewController(alertController, animated: true, completion: nil)

}


5、建立代码和按钮间的连结

按着control键不方,点选按钮,拖拉到View Controller的图标上,选择刚才写好的方法showMessage做为动作连结。

6、完成,可以直接测试了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: