ios - Auto Layout using initWithFrame? -


if i'm implementing autolayout programatically in ios proper use initwithframe method? if not how initialise view of preferred size?

better avoid initwithframe unless have no choice. auto layout, approach define 2 constraints specify width , height. there's different ways if you're doing programmatically, in updateviewconstraints method of view controller, or updateconstraints method of view, check if constraints have been created , if not, add them view.

e.g.

[myconstraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"h:|-[_mysubview]-(200)-|"                                  options:0                                  metrics:nil                                  views:_myviewsdictionary]];  [myconstraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:|-[_mysubview(100)]-|"                                  options:0                                  metrics:nil                                  views:_myviewsdictionary]]; 

that said, better using interface builder. once used - , take getting used - you'll find fantastic timesaver , better defining constraints in code.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -