iOS模拟器上运行的简单视图应用(空白的应用程序)
发表时间:2023-09-26 14:02:05
文章来源:炫佑科技
浏览次数:144
菏泽炫佑科技
iOS模拟器上运行的简单视图应用(空白的应用程序)
创建您的**个应用程序
现在让我们创建一个在 iOS 模拟器上运行的简单视图应用程序(空白应用程序)。
步骤如下:
1.打开Xcode并选择创建一个新的Xcode项目。
2.然后选择单视图应用程序
3. 接下来输入产品名称iOS模拟器上运行的简单视图应用(空白的应用程序),即应用程序名称、组织名称和公司标识符。
4. 确保选择“自动应用计数”以自动释放范围外的资源。 点击下一步。
5.选择项目目录并选择创建
6.您将看到如下所示的页面
方向、生成和释放可以在屏幕顶部设置。 有一个部署目标,设备支持4.3及以上版本的部署目标,这些不是必需的,现在只关注运行应用程序。
7. 在下拉菜单中选择并运行。
8. 成功运行**个应用程序后,您将得到如下所示的输出。
更改背景颜色以启动 。 选择.xib。 选择右侧的背景选项,更改颜色并运行。
在上面的项目中,部署目标已设置为iOS6.0,并且默认启用自动布局。
为了确保应用程序能够在iOS 4.3设备上正常运行,我们在开始创建应用程序时修改了部署目标,但我们没有禁用自动布局。 要取消自动布局,我们需要取消选择查看器的每个nib文件中的自动类复选框,该文件是一个xib文件。
Xcode项目IDE的各个部分如下所示(Apple用户文档)
文件检查器可以在上面显示的检查器选择器栏中找到,并且可以取消选择自动布局。 当您只想定位 iOS6.0 设备时软件制作,可以使用自动布局。
当然,新功能也是可用的,例如添加到iOS6时。 现在,使用iOS4.3作为部署目标。
深入了解**个iOS应用程序代码 5个不同的文件生成应用程序如下所示
我们使用单行注释(//)来解释简单的代码,重要的项目代码解释在代码下方。
。H
// Header File that provides all UI related items. #import// Forward declaration (Used when class will be defined /imported in future) @class ViewController; // Interface for Appdelegate @interface AppDelegate : UIResponder // Property window @property (strong, nonatomic) UIWindow *window; // Property Viewcontroller @property (strong, nonatomic) ViewController *viewController; //this marks end of interface @end
代码说明.m
// Imports the class Appdelegate's interface import "AppDelegate.h" // Imports the viewcontroller to be loaded #import "ViewController.h" // Class definition starts here @implementation AppDelegate // Following method intimates us the application launched successfully - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; 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
代码说明.h
#import // Interface for class ViewController @interface ViewController : UIViewController @end
代码说明.m
#import "ViewController.h" // Category, an extension of ViewController class @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
代码说明