ios - How to properly position a UITableView cell subview to the right? -
so i'm trying add uiswitch table cells on right. first tried adding accesoryview, when entered editing mode in table, uiswitch dissapeared. added contentview, working great, no dissapearing. adds top left corner.
so i'm trying add right want stay away of absolute values in order support sizes , orientations.
so i'm trying code:
[[cell contentview] addsubview:switchview]; switchview.frame = cgrectmake(cell.contentview.frame.size.width - switchview.frame.size.width, 0, switchview.frame.size.width, switchview.frame.size.height);
but i'm getting:
any ideas how can fix this?
you need set appropriate autoresizing masks or layout constraints on switch.
if you're using springs , struts, want switch have flexible left margin only. keep fixed distance right hand edge of superview - content view resized between adding switch , appearing on screen.
to set mask:
switchview.autoresizingmask = uiviewautoresizingflexibleleftmargin;
if you're using auto layout (which makes not using specific frame values easy!), need pin switch right edge of superview - [switch]-|
in visual format.
Comments
Post a Comment