Reputation: 901
I have a table cell that will have a description and a title label. i want to description label to fit the text to a max of 3 lines and the title to do the same but with 2 line max. and this i can achieve. What i am having problem doing is making the description stick to the bottom and the title over the description as show bellow.
i found a solution to do it with the the frame, but i wanted to know if it is possible to achieve this just with auto layout
Upvotes: 2
Views: 1639
Reputation: 204
Using auto layout you can achieve it by setting following constraints.
Set constant height constraint for both description, title labels.
Select description label and go to size inspector,set content hugging priority, content compression resistance priority vertical values to 1000.
In size inspector below these priorities you can see constraints. Click the down arrow on right side of height constraint and choose "select and edit". And set priority less than 1000. (say 800). By default it will be 1000.
Repeat steps 4,5 for title label.
In attribute inspector set "Lines" to 2 for title lanel and 3 for description label. (If you set lines to 0, it will show full content)
Hope this helps.
Upvotes: 4
Reputation: 319
Yes, It is possible in storyboard you choose NumberOfLines property for TitleLabel be 0 and choose LineBreks as you want means it automatically fit any number of lines depending upon text by addingConstraints called leadingSpaceToContainerMargin,TopSpace To TopLayoutGuide,Width is set to Equal,Height is set to GreaterThanOrEqual.
For Description label also set NumberOfLines property for TitleLabel be 0 and choose LineBreks as you want and add constraints like leadingSpaceToContainerMargin,VerticalSpacing, Width is set to Equal,Height is set to GreaterThanOrEqual.
Upvotes: 1