我正在向UITableViewCell添加一个UITextField,并通过以下约束对齐它:
[cell addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:cell.textLabel attribute:NSLayoutAttributeTrailing multiplier:1 constant:8]];
[cell addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:8]];
[cell addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:-8]];
[cell addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTrailing multiplier:1 constant:-16]];
这很好用,直到我旋转视图。 UITextField并没有与单元格紧密相关。我只是缺少约束吗?
答案 0 :(得分:0)
仅供参考我添加:
cell.contentView.autoresizingMask = UIViewContentModeScaleAspectFit;
到UITableCell并修复它!