Wednesday, 15 September 2010

iphone - Auto Layout (Constraints) Center 2 side by side views in a parent view -



iphone - Auto Layout (Constraints) Center 2 side by side views in a parent view -

i'm trying figure out how auto layout (ios6) , constraints.

basically have big view divided 2 sections on bottom. within of sections (currently subviews) have image view , label. want center on both sides, variable length text.

my head wrapped around auto layout, i'm not sure best approach this. i'm inclined think it's not possible in ib, in code.

going go on trying figure out, in meantime here illustration i'm trying create.

is you're after?

i did adding view (named viewcenteredinleftsection) within leftsection, adding clock image , label subviews these constraints:

make viewcenteredinleftsection's centerx , centery equal superview's (leftsection). make clockimage's top, bottom, , leading edges equal superview's (viewcenteredinleftsection). make label's trailing border equal superview's (viewcenteredinleftsection). make clockimage's trailing border standard distance away label's leading edge.

i have problem resizing ios uiviews in interface builder, made illustration os x, , able exclusively in interface builder. if have problem making above constraints in interface builder, allow me know, , i'll post code that'll create them.

2014-08-26 edit

luda, here xcode 5's pin , align menus, available in xcode's menu bar:

below illustration looks in interface builder. bluish view "parent view" original question, given view in image , label should centered.

i added greenish view (which named viewcenteredinleftsection) subview of "parent view". highlighted , used align menus "horizontal center in container" , "vertical center in container" create constraints define position.

i added clock image subview of viewcenteredinleftsection, constraints defining width , height. highlighted clock image , viewcenteredinleftsection, applied constraints using align > leading edges, align > top edges, , align > bottom edges.

i added label subview of viewcenteredinleftsection, positioning standard aqua space distance clock image. highlighted label , viewcenteredinleftsection, applied constraints using align > trailing edges.

this much easier create xcode 5's interface builder versus xcode 4's.

iphone ios constraints autolayout

No comments:

Post a Comment