0

I'm trying to display rows containing a thumbnail and a title.

It works great for short title strings, but for long strings, it breaks. Rather than expanding horizontally, I would prefer it to expand vertically. Checkout the screenshot below to see what happens when a long string is used. I'm using PureLayout to manage Auto Layout:

thumbnailView.autoSetDimensions(to:CGSize(width: 75, height: 75))
thumbnailView.autoPinEdge(toSuperviewEdge: .leading, withInset: kLabelHorizontalInsets)
thumbnailView.autoPinEdge(toSuperviewEdge: .top, withInset: kLabelVerticalInsets)
thumbnailView.autoPinEdge(toSuperviewEdge: .bottom, withInset: kLabelVerticalInsets, relation: .greaterThanOrEqual)

titleLabel.autoPinEdge(.leading, to: .trailing, of: thumbnailView, withOffset: kLabelHorizontalInsets, relation: .lessThanOrEqual)
titleLabel.autoPinEdge(toSuperviewEdge: .top, withInset: kLabelVerticalInsets)
titleLabel.autoPinEdge(toSuperviewEdge: .trailing, withInset: kLabelHorizontalInsets)
titleLabel.autoPinEdge(toSuperviewEdge: .bottom, withInset: kLabelVerticalInsets)

The appropriate settings on the UITextLabel are also set:

 titleLabel.lineBreakMode = .byWordWrapping
 titleLabel.numberOfLines = 0
 titleLabel.textAlignment = .left

Any suggestions are appreciated. Thanks tableview screenshot

user339946
  • 5,961
  • 9
  • 52
  • 97
  • Why are you using `.lessThanOrEqual` for the leading constraint of your label? – Paulw11 Mar 13 '17 at 00:52
  • @Paulw11 I want there to be a minimum margin between the label and the thumbnail – user339946 Mar 13 '17 at 00:58
  • Ok, but you don't want `.lessThanOrEqual`. That says that the margin must be `kLabelHorizontalInsets` **or less**. -20 is less. You just want the margin to be `kLabelHorizontalInsets` so remove the `relation` parameter – Paulw11 Mar 13 '17 at 01:15

2 Answers2

1

You don't need to restrict top and bottom constraint. The UILabel will auto adjust the contentHeight. You can refer to contentHuggingPriorityForAxis: and contentCompressionResistancePriorityForAxis:. You can fix the center of label rather than the bottom and top.

kai
  • 310
  • 3
  • 14
0

Found one possible solution: solution

Turns out UILabel's numberOfLines property and Auto Layout don't play along nicely.

Community
  • 1
  • 1
user339946
  • 5,961
  • 9
  • 52
  • 97