我还没有找到如何让我的视图填充可用空间作为UINavigationController
. 我正在尝试在这里使用 AutoLayout,但我怀疑这就是问题所在。在我的应用委托中
- (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;
}
而在我的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]];
}
并且标签在屏幕中居中而不是绑定到左上角,因为我相信视图只是在屏幕中居中而不是填充可用空间。