我正在尝试将自动布局合并到我的UITableViewHeaderFooterView子类中.这个课程非常基础,只有两个标签.这是完整的子类:
@implementation MBTableDetailStyleFooterView
static void MBTableDetailStyleFooterViewCommonSetup(MBTableDetailStyleFooterView *_self) {
UILabel *rightLabel = [[UILabel alloc] init];
_self.rightLabel = rightLabel;
rightLabel.translatesAutoresizingMaskIntoConstraints = NO;
[_self.contentView addSubview:rightLabel];
UILabel *leftLabel = [[UILabel alloc] init];
_self.leftLabel = leftLabel;
leftLabel.translatesAutoresizingMaskIntoConstraints = NO;
[_self.contentView addSubview:leftLabel];
NSDictionary *views = NSDictionaryOfVariableBindings(rightLabel, leftLabel);
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[leftLabel]-(>=10)-[rightLabel]-10-|" options:0 metrics:nil views:views];
[_self.contentView addConstraints:horizontalConstraints];
// center views vertically in super view
NSLayoutConstraint *leftCenterYConstraint = [NSLayoutConstraint constraintWithItem:leftLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
[_self.contentView addConstraint:leftCenterYConstraint];
NSLayoutConstraint *rightCenterYConstraint = [NSLayoutConstraint constraintWithItem:rightLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY …Run Code Online (Sandbox Code Playgroud)