I am trying to center a view using the visual format language.
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[_progressView(300)]-|" options:NSLayoutFormatAlignAllCenterY metrics:0 views:views]];
(views
is a NSDictionaryOfVariableBindings
containing _progressView
)
It does not center my view (width: 300) within the self.view
(width: 768). It aligns it left with an 8 pixel margin, as if I would have only written @"H:|-[_progressView(300)"
.
Is the only way to center the view using something like:?
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_progressView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual
toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
Thanks