ios - Custom UITableViewCell with auto layout issue -
i have custom uitableviewcell
seen below:
my image has fixed width , height, description label fills remaining width , has automatic height based on content.
this creates problem because, depending on description label’s height, there’s never fixed anchor attach bottom of cell to.
so, have constraint bottom of image bottom of cell’s margin, relation of >= 0. similarly, have constraint on bottom of description label relation of >= 0.
however, when run app auto layout uses image constraint calculate bottom instead of description label constraint, when when description label taller. clips label.
i have feeling might content hugging , compression resistance both views 251 , 750 respectively. (i’ve toyed around these no luck - don’t understand them)
how use auto layout attach bottom of cell image when description smaller image? , vice versa?
you can remove bottom constrain label , set vertical content hugging , vertical content compression 1000 (required). tells label can have unlimited vertical height long hugs content. problem if description long go pass cell bottom causing text cut midline. avoid headache, set the label's max line number , line break mode "truncate tail".
this assume don't mind description text getting cut. if want cell's height dynamically change according content that's different story.
for dynamic cell height, change bottom constrain of image , description label == add these 2 methods viewcontroller:
-(cgfloat)tableview:(uitableview *)tableview estimatedheightforrowatindexpath:(nsindexpath *)indexpath{ return 100; // min cell height } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{ return uitableviewautomaticdimension; }
Comments
Post a Comment