第一个swift ios案例体验

第一个swift ios案例体验,第1张

概述OS: OS X Yosemite Version 10.10 IDE:XCode 7.0.1 对于每一个Swift的新手来说,第一个写的程序都必须是Hello World,这里只是简单的描述了一下怎么创建一个新工程并实现按钮显示Hello World的简单功能。 1. 新建工程HelloWorld     打开Xcode,选择Create a new Xcode project 2. 打开模板窗

OS: OS X Yosemite Version 10.10

IDE:XCode 7.0.1


对于每一个Swift的新手来说,第一个写的程序都必须是Hello World,这里只是简单的描述了一下怎么创建一个新工程并实现按钮显示Hello World的简单功能。


1. 新建工程HelloWorld

打开Xcode,选择Create a new Xcode project


2. 打开模板窗口,选择Single VIEw Application

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="337" wIDth="570" src="http://img.blog.csdn.net/20141020171629803">



3. 输入项目名字“Helloworld”,然后Language里面选择Swift

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="335" wIDth="570" src="http://img.blog.csdn.net/20141020171737164">



4. 保存项目到本地路径,自己随便选择一个目录呗

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="544" wIDth="570" src="http://img.blog.csdn.net/20141020171844588">



5. 保存之后自动打开的就是这个界面了,里面是项目工程的一些设置,直接用默认的就可以了

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="356" wIDth="570" src="http://img.blog.csdn.net/20141020171937534">



6. 单击左边目录结构的“Main.storyboard”,打开如下主界面,这个就是你的程序打开时候的默认界面了

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="355" wIDth="570" src="http://img.blog.csdn.net/20141020172112148">



7. 现在往界面里面添加一个button跟一个Label,控件都在右下角的那个Panel里面,并button文字设置为“OK”

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="356" wIDth="570" src="http://img.blog.csdn.net/20141020172201453">



8. 接下来我们要往button里面添加一个按键事件,按下button之后在Label上显示 “Hello World!”

在button控件上右键,单击“Sent Events”下面的“touch Down”右边的圈圈,把它拉到右边代码区域,Xcode会d出下面的输入框,在“name”里面输入“o'clock”,然后connect创建事件。

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="348" wIDth="570" src="http://img.blog.csdn.net/20141020173008196">


650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="346" wIDth="570" src="http://img.blog.csdn.net/20141020172755515">


650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" height="355" wIDth="570" src="http://img.blog.csdn.net/20141020173323789">


创建代码如下:

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173411448">


9. 用同样的方式,给Label创建一个变量

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173241421">


650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173640599">



代码如下:

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173514768">



10. 创建了控件的事件之后,就可以在代码里实现按钮触发事件如下:

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173742766">



代码如下:

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173847786">


11. 运行效果如下

650) this.wIDth=650;" src="http://img.jb51.cc/vcimg/static/loading.png" alt="" src="http://img.blog.csdn.net/20141020173917270">

总结

以上是内存溢出为你收集整理的第一个swift ios案例体验全部内容,希望文章能够帮你解决第一个swift ios案例体验所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1081106.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存