iOS开发1-Hello World

本文是iOS开发的入门教程,通过Xcode创建一个简单的Hello World应用。内容包括设置开发环境,使用Xcode创建项目,创建并配置项目信息,添加Label展示'Hello World!',以及为应用添加图标和启动页。通过这个过程,了解iOS应用的基本构建步骤和界面设计。
摘要由CSDN通过智能技术生成

目标

到现在开始,正式开始编写iPhone程序了。
这里将使用Xcode创建一个小型的iOS应用,在模拟设备屏幕上显示文本“Hello World!”。
实现的效果:
这里写图片描述

内容

1.开发环境

虽然iOS9已经出了,但这里还是以iOS8来做的开发教程。
Xcode7终于可以直接真机调试了,福音啊,但是这里还是Xcode6来写的哦。

操作系统:OS X 10.9.5
编译器 :Xcode 6.1.1

这里写图片描述

2.在Xcode中创建项目

安装Xcode俺就不说了。

2.1创建项目

1)打开Xcode,会出现欢迎界面
点击左边的Create a new Xcode project 创建一个新的项目。
欢迎界面中,左边是创建项目,右边是近期打开的项目。
这里写图片描述

2)选择项目模板。
iOS应用开发所以选择iOS下的Application(应用),从中选择Single View Application(空视图应用)。
Application->Single View Application->Next
这里写图片描述

3)填写新建项目信息。
Product Name:(项目名称)
Organization Name:(组织名称)
Organization Identifier:(组织ID)一般为公司网址倒过来写,Java的包名一样。
Bundle Identifier:(包ID)=组织+程序名,程序开发包的ID。
Language:(开发语言)有OC和Swift,这里选择OC,Swift以后介绍。
Device:(开发的设备)
这里写图片描述
4)选择项目文件保存位置。
这里写图片描述
5)Xcode项目窗口。
这就是项目创建完成后出现的界面了,和所有的IDE都差不多。

// // 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 state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // 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. } - (void)applicationDidBecomeActive:(UIApplication *)application { // 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. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值