Skip to content

Commit bf36877

Browse files
Tyler FoxTyler Fox
authored andcommitted
Change 1 cell constraint to an inequality to resolve ambiguous layout
1 parent 8401a88 commit bf36877

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ - (void)updateConstraints
8484
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
8585
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
8686

87+
// This is the constraint that connects the title and body labels. It is a "greater than or equal" inequality so that if the row height is
88+
// slightly larger than what is actually required to fit the cell's subviews, the extra space will go here. (This is the case on iOS 7
89+
// where the cell separator is only 0.5 points tall, but in the tableView:heightForRowAtIndexPath: method of the view controller, we add
90+
// a full 1.0 point in extra height to account for it, which results in 0.5 points extra space in the cell.)
91+
// See https://github.com/smileyborg/TableViewCellWithAutoLayout/issues/3 for more info.
92+
[self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets relation:NSLayoutRelationGreaterThanOrEqual];
93+
8794
[self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
88-
[self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets];
8995
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
9096
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
9197
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

0 commit comments

Comments
 (0)