2014-12-09 66 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; 

我希望它會工作...