iOS开发 从一个空项目创建ViewController和xib

AppDelegate.h
#import 
#import "MainViewController.h"
@interface BIDAppDelegate : UIResponder 
 
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) MainViewController * controller;
 
@end




AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.controller= [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
 
    UIView *mainView=self.controller.view;
    CGRect mainViewFrame=mainView.frame;
    mainViewFrame.origin.y+=[UIApplication sharedApplication].statusBarFrame.size.height;
    //将y座标移到状态栏下
    mainView.frame=mainViewFrame;
    [self.window addSubview:mainView];
    //载入
 
 
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

你可能感兴趣的:(iOS开发 从一个空项目创建ViewController和xib)