ios xib文件使用

来源:互联网 发布:英语口语精华软件 编辑:程序博客网 时间:2024/04/29 01:20

xib虽然已经过时,但维护旧的ios应用时会遇到。


使用方式


1、创建ios工程


2、创建Cocos touch文件,继承自UIViewController,并勾选 Also create xib file,文件名假设为MyViewController

创建完成后工程结构


3.xib文件中拖拉控件



4、AppDelegate.m文件

////  AppDelegate.m//  viewcollection////  Created by Young on 15/10/9.//  Copyright (c) 2015年 Young. All rights reserved.//#import "AppDelegate.h"#import "MyViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.        //创建UIWindow,大小为screen大小    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];        //调用UIViewController的initWithNibName方法,使用MyViewController.xib文件创建ui    UIViewController* rootControl=[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];        //设置根rootViewController    self.window.rootViewController=rootControl;    //设为可见    [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


运行效果




0 0
原创粉丝点击