Nslayoutconstraint所有按钮对齐

时间:2015-08-23 17:27:46

标签: uitableview nslayoutconstraint

我想在UItableViewCell

中添加两个按钮

但是通过添加自动布局代码,两个按钮没有对齐到右侧?

我的代码会发生什么?

CGSize winSize = [[UIScreen mainScreen] bounds].size;
NSDictionary *metrics   = @{ @"width":@(44)};

NSDictionary *viewsDictionary = @{@"myAddButton":myAddButton,
                                  @"myDeleteButton":myDeleteButton};

NSMutableArray *myConstraints = [NSMutableArray array];

[myConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[myDeleteButton(width)]-5-[myAddButton(width)]-10-|" options:0 metrics:metrics views:viewsDictionary]];

[self.contentView addConstraints:myConstraints];

[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:myAddButton
                                                             attribute:NSLayoutAttributeCenterY
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.contentView
                                                             attribute:NSLayoutAttributeCenterY
                                                            multiplier:1.f constant:0.f]];

[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:myDeleteButton
                                                             attribute:NSLayoutAttributeCenterY
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.contentView
                                                             attribute:NSLayoutAttributeCenterY
                                                            multiplier:1.f constant:0.f]];

[self setNeedsLayout];

0 个答案:

没有答案