I have a tableview cell with two labels and a small image. If the labeltexts are short, all fits in one row like this:
.________________________________________.
| |
| [firstlabel] [img] [secondlabel] > |
|________________________________________|
However, if the labeltexts are getting longer, the image and the second label should move to the second line:
.________________________________________.
| |
| [firstveryverylonglabel] > |
| [img] [secondverylonglabel] |
|________________________________________|
How would I do this with autolayout?
The first label is easy - just add constraints for left and top. Labels are always only one line heigh, and get truncated in the middle if the text gets way too long.
The image must always be in front of the second label (default space) horizontally, and both centered vertically. The image size should scale with the dynamic text font size (preferredFontForTextStyle:UIFontTextStyleBody) of the labels, so that if the user chooses large text the image also gets drawn larger.
The cell height should of course grow if two lines are needed.
Bonus Points if setting the necessary constraints would be possible in Interface Builder, but if not then I could set them with code in the init routine of the tableview cell.
My app should run under iOS 7 and later - no need for iOS 6. So I must compute the height in tableview:heightForCellAtIndexPath:, and will use a hidden cell to let Autolayout do its magic there.