/* Note that I have uncommented Line 9 to prevent constraint exceptions before the cells actually layout at their correct size. */ - (void)updateConstraints { if (!self.didSetupConstraints) { // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f); // the image view is pinned to the edges of the content view with a 15px inset // this should be enough to force the height of the content view [self.mainImage autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(15, 15, 15, 15)]; // if you set a fixed height constraint, there is no problem, the cell's // contentView height is pushed out to fit this constraint // [self.mainImage autoSetDimension:ALDimensionHeight toSize:100]; // make the height of the image view equal to 0.5 the width of the contentView. This // doesn't result in 'forcing' the cell's contentView height [self.mainImage autoMatchDimension:ALDimensionHeight toDimension:ALDimensionWidth ofView:self.contentView withMultiplier:0.5 relation:NSLayoutRelationGreaterThanOrEqual]; // [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ // [self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; // }]; // [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets]; // [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; // [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; // // // 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 // // 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 // // where the cell separator is only 0.5 points tall, but in the tableView:heightForRowAtIndexPath: method of the view controller, we add // // a full 1.0 point in extra height to account for it, which results in 0.5 points extra space in the cell.) // // See https://github.com/smileyborg/TableViewCellWithAutoLayout/issues/3 for more info. // [self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets relation:NSLayoutRelationGreaterThanOrEqual]; // // [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ // [self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; // }]; // [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; // [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; // [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets]; self.didSetupConstraints = YES; } [super updateConstraints]; }