2014-12-09 60 views
0

我已经开始开发没有界面构建器的iOS。iOS UIViewController布局问题

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    ViewController *viewController = [[ViewController alloc] init]; 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    self.window.rootViewController = viewController; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

ViewController.m

- (void)loadView 
{ 
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 
    UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame]; 
    contentView.backgroundColor = [UIColor whiteColor]; 
    self.view = contentView; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 20)]; 
    [label setText:@"ViewController"]; 
    [label setTextAlignment:NSTextAlignmentCenter]; 
    [label setBackgroundColor:[UIColor redColor]]; 
    [self.view addSubview:label]; 
} 

我不知道为什么,但是当我加载应用程序,有顶蚂蚁钮和视图之间的空间。有没有人有一个想法,为什么?

enter image description here

+0

您需要将[email protected]背景图片添加到项目 – 2014-12-09 12:15:05

+0

我刚刚在6加模拟器中运行您的代码。我没有看到黑色区域 – humblePilgrim 2014-12-09 12:18:55

+0

@Gonji Dev,您的回答是正确的!如果您发布它,我会将其标记为正确! – 2014-12-09 12:21:07

回答

0

如果您的部署目标是iOS的7.0起刚刚检查。

self.edgesForExtendedLayout = UIRectEdgeNone; 

我希望它会工作...