objective c - How to programmatically position and size subviews into cell's contentView -
i cell frame
@ tableview:cellforrowatindexpath:
in order position , size views want add uitableviewcell
's contentview
. there self.frame
(0, 0, 320, 44)
.
i know can right frame
in layoutsubviews
(thanks this answer), if add subviews there done every time cell reused, not once in "official" example @ programmatically adding subviews cell’s content view.
in example add views using hardcoded frames like:
mainlabel = [[uilabel alloc] initwithframe:cgrectmake(0.0, 0.0, 220.0, 15.0)];
i guess example outdated, since should use constraints, or @ least calculate size of subviews using actual cell frame
(which may impossible @ point indeed).
note: reminds me of view holder design pattern used in android.
this should return bounding frame.
cgrect cellframe = cell.bounds;
then can use like
cellframe.size.width; cellframe.size.height; cellframe.origin.x; cellframe.origin.y;
etc... though origin.x , origin.y should 0 each.
maybe should calculate cell height in uitableviewcell subclass , use
-(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath
in delegate find correct height.
Comments
Post a Comment