I'm looking to do a table view cell with a photo and wrapping text with auto layout. I've managed a lot with auto layout, but I'm at a loss on how to do this one.
┌─────────────────────────────────────────────────────┐
│ ┌──────────┐ ┌────────────────────────────────────┐ │
│ │ │ │ Title (might wrap) │ │
│ │ │ └────────────────────────────────────┘ │
│ │ Photo │ ┌────────────────────────────────────┐ │
│ │ │ │ Body text. May wrap, may contain │ │
│ │ │ │ multiple lines. │ │
│ │ │ └────────────────────────────────────┘ │
│ └──────────┘ │
└─────────────────────────────────────────────────────┘
As the text expands, I want to keep the photo in the top left and expand the cell. However, the cell should never shrink below the minimum required to show the photo (with margins).
┌─────────────────────────────────────────────────────┐
│ ┌──────────┐ ┌────────────────────────────────────┐ │
│ │ │ │ Title (might wrap) │ │
│ │ │ │ Maybe even to two lines. │ │
│ │ Photo │ └────────────────────────────────────┘ │
│ │ │ ┌────────────────────────────────────┐ │
│ │ │ │ Body text. May wrap, may contain │ │
│ │ │ │ multiple lines. │ │
│ └──────────┘ │ │ │
│ │ Text could require more vertical │ │
│ │ space than the photo. │ │
│ └────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
I'm requiring iOS 8 or later.
I've tried doing this with just the three views listed, and also by putting the left item and right items in two views. Every combination I try seems to ignore the photo's minimum size.
(Btw, for anyone curious: Graphic via Monodraw.)
Try having the following relationships:
Photo:
Title:
the label will auto calculate the height based on content
Body:
Cell: (this is the important part)
this will force the cell to be, at all times, either taller than the image + offset or taller than the label + offset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With