Auto Layout iOS 7 - не удается выровнять право подпредставления справа от UIScrollView
Я программно строю представление и использую autolayout, никакого построителя интерфейса вообще. В пользовательском контроллере ScrollView я добавляю UILabel и UIButton в качестве подпредставлений. Я хочу выровнять метку слева от экрана, а кнопку справа от экрана. По какой-то причине моя кнопка выравнивается только слева от моего прокрутки. Я сократил свой код так, чтобы это были только эти две метки, и я не могу понять, почему он не выровняется по правому краю.
HWScrollViewController.m (Как я инициализирую основное представление прокрутки)
- (void)loadView
{
self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.scrollView.delegate = self;
self.view = self.scrollView;
}
HWListingDetailViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *priceLabel = [[UILabel alloc] init];
UIButton *favouriteButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[priceLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[favouriteButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[priceLabel setText:@"$125.00"];
[favouriteButton setTitle:@"Add to Favourites" forState:UIControlStateNormal];
[self.view addSubview:priceLabel];
[self.view addSubview:favouriteButton];
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:priceLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0],
[NSLayoutConstraint constraintWithItem:priceLabel
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1
constant:5],
[NSLayoutConstraint constraintWithItem:favouriteButton
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0],
[NSLayoutConstraint constraintWithItem:favouriteButton
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1
constant:5],
}
Как видите, зеленая метка цены выровнена правильно, но красная кнопка находится далеко от левой стороны экрана. (Я дал ему 5 пикселей смещения, чтобы показать, где он был.) Итак, почему правая сторона прокрутки фактически является левой стороной? Как правильно настроить выравнивание по правому краю экрана? Где я неправ? Это сводит меня с ума!
Спасибо за любую помощь!
Окончательные изображения макета: я надеюсь, что окончательный макет будет примерно таким:
и я ожидаю, что это будет выглядеть так, если повернуть в ландшафт: