swift语言ios开发 第一个程序hello world!

老实说:第一个swift语句的ios不是代码敲出来的,我甚至还没来得急看代码,hello world 就出来了。。。。。

 

本人开发环境:mac osx 10.10 dp1 + xcode beta + swift(更低xcode不支持swift语言)

 

思路与大致过程:

       1、建立工程,工程包含界面文件,代码文件等等

        2、在工程的界面文件中加入text控件,用于显示hello world

        3、输入hello world ,模拟运行

 

 

让我们一步一步来:

  1、建立工程,工程包含界面文件,代码文件等等

点击 File-new-project 创建工程

 

 

 

 2、选择工程类型  我们选择single  view application(单视图应用)

 

 

 

3、对工程进行配置如图  选择swift语言

 

 

 

4、点击next 选择工程代码等文件存放地点

存放在我的文档,点击creat按钮

 

 

5、创建成功后在左边视图中展开工程文件,看到一个Main.storyboard,这就是界面控制视图文件,用来设计软件界面的,我们单击之(双击会将该面板作为独立窗口显示,不方便添加控件):

 

 

6、单击main.storyboard后显示:

 

 

7、在右下角面板中选择第三个按钮,得到控件列表 如下图红色笔记

 

 

 

 

选择该按钮后下面是控件列表,滚动鼠标下拉找到text控件,拉到窗口中即可

 

 

 

9、然后点击文本框,输入fuck swift 即可,点击左上角运行按钮即可编译运行(编译需要短暂时间):

 

10、结果图

 

 

因为这个程序太简单,所以整个过程就没代码什么事情.......

 

打个小广告:本人精通各类操作系统的安装与维护,包括在普通pc机(联想宏碁等)安装mac os x系统(还有大把软件),100元/次不二价,欢迎北京朋友咨询qq1752209254

有意请短信先咨询:18510222924 

ps :支持多系统安装,即开机时可选择进入哪个操作系统(win+linux各种版本+mac os x)

本教程截图就是黑苹果机子。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
// // main.m // Hello World_Code // #import #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } // // AppDelegate.h // Hello World_Code // #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end // // AppDelegate.m // Hello World_Code // #import "AppDelegate.h" @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(320/2.0 - 140/2.0, 80, 140, 40)]; // 1 label.text = @"Hello World"; label.backgroundColor = [UIColor cyanColor]; label.textAlignment = NSTextAlignmentCenter; [self.window addSubview:label]; // 2 [label release]; // 1 return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // 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. // 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. } - (void)applicationDidEnterBackground:(UIApplication *)application { // 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
以下是iOS平台上的Hello World示例代码: 1. 打开Xcode,创建一个新的iOS项目。 2. 在项目创建向导中选择Single View App,并点击Next。 3. 为你的项目指定名称,选择你要存储的位置,然后点击Next。 4. 在接下来的屏幕上,你可以选择使用Swift或Objective-C编写代码。选择你喜欢的编程语言,然后点击Next。 5. 最后,点击Create来创建你的项目。 6. 在Xcode中打开ViewController.swift或ViewController.m文件。 7. 在文件中,你可以看到一个类似于下面的代码: Swift: ```swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } } ``` Objective-C: ```objc #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } @end ``` 8. 在`viewDidLoad`方法中添加以下代码: Swift: ```swift let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) label.center = CGPoint(x: 160, y: 284) label.textAlignment = .center label.text = "Hello, World!" self.view.addSubview(label) ``` Objective-C: ```objc UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 21)]; label.center = CGPointMake(160, 284); label.textAlignment = NSTextAlignmentCenter; label.text = @"Hello, World!"; [self.view addSubview:label]; ``` 9. 运行你的应用程序。你应该会看到一个显示“Hello, World!”的标签。 这就是在iOS平台上创建Hello World应用程序的简单过程。这只是一个基本的示例,你可以通过添加更多的控件和代码来扩展它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值