iOS UIViewController layout issue

Jacob Jones

I have started to develop iOS without interface builder.

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];
}

I don't know why, but when I load application, there is space between top ant botton and view. Does anyone has an idea why?

enter image description here

Fabio Felici

You need to add the [email protected] background image to the project.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related