I did not find how to make my view fill the available space as the root view controller (or the pressed view controller) in the UINavigationController . I am trying to use AutoLayout here, but I doubt the problem. In my application delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ViewController *viewController = [[ViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; }
And in my ViewController
- (void)viewDidLoad { [super viewDidLoad]; self.view.translatesAutoresizingMaskIntoConstraints = NO; // Do any additional setup after loading the view, typically from a nib. UILabel *companyLabel = [[UILabel alloc] init]; companyLabel.translatesAutoresizingMaskIntoConstraints = NO; companyLabel.text = @"We Build It"; companyLabel.backgroundColor = [UIColor redColor]; [self.view addSubview:companyLabel]; NSDictionary *views = NSDictionaryOfVariableBindings(companyLabel); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[companyLabel]" options:0 metrics:@{} views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[companyLabel]" options:0 metrics:@{} views:views]]; }
And the shortcut is centered on the screen instead of snapping to the upper left corner, because, in my opinion, the view is simply focused on the screen instead of filling the available space.
source share