I am building a very simple App.net client as a sort of test app. It simply pulls the latest 20 posts from the App.net public timeline and displays the post, the user's name, and the user's avatar in a UITableView
. Simple enough.
For the UI, I am using a storyboard and Auto Layout.
UIImageView
Constraints
- Height Equals: 69
- Width Equals: 69
- Align Top to: Label - Name (the username label)
- Leading Space to: Superview Equals: 3
- Trailing Space to: Label - Name Equals: 8
- Trailing Space to: Label - Text (the text of the post) Equals: 8
Name Label Constraints
- Align Top to: Image View
- Top Space to: Superview Equals: 5
- Trailing Space to: Superview Equals: 17
- Leading Space to: Image View Equals: 8
- Bottom Space to: Label - Text Equals: 6
Text Label Constraints
- Bottom Space to: Superview Equals: 9
- Trailing Space to: Superview Equals: 17
- Top Space to: Label - Name Equals: 6
- Leading Space to: Image View Equals: 8
Finally, to set the height of each cell, I am using the following code in tableView:heightForRowAtIndexPath:
:
// Solution greatly helped by http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-heights
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
static ADNPostTableViewCell *cell;
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:@"PostCell"];
}
cell.post = self.posts[indexPath.row];
return fmax([cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height, cell.avatarImageView.frame.size.height + kImageViewPadding); // kImageViewPadding = 5
}
For Portrait, this works wonderfully. I get the following:
For Landscape, however, a very peculiar padding appears (a large amount of whitespace in between the Name label and the Text label and in between the Text label and the bottom cell divider), and I have no idea how to figure out what constraint is causing this. I've tried a wide variety of constraints, but I still can't seem to get rid of the padding.
Thanks in advance, and please let me know if there's anything else I can provide to assist in solving this problem!