i have come appreciate work auto layout me, i'm brent simmons on topic of not using interface builder set constraints. interface provided apple flexible extremely verbose — designed code generator instead of human use. me exemplifies worst of objective-c repeating overlong identical prefixes , used parameters obfuscating meaning instead of providing clarity code. i've seen florian kugler's flkautolayout hides constraint creation in category on uiview
.
are there other ways make layout constraints in code cleaner , easier understand?
masonry jonas budelmann dsl auto layout more readable lines , lines of layout constraints being created manually. via ios dev weekly.
uiedgeinsets padding = uiedgeinsetsmake(10, 10, 10, 10); [view1 mas_makeconstraints:^(masconstraintmaker *make) { make.top.equalto(superview.mas_top).with.offset(padding.top); make.left.equalto(superview.mas_left).with.offset(padding.left); make.bottom.equalto(superview.mas_bottom).with.offset(-padding.bottom); make.right.equalto(superview.mas_right).with.offset(-padding.right); }];
it has composite constraints setting edges, size , center:
// make top, left, bottom, right equal view2 make.edges.equalto(view2); // make top = superview.top + 5, left = superview.left + 10, // bottom = superview.bottom - 15, right = superview.right - 20 make.edges.equalto(superview).insets(uiedgeinsetsmake(5, 10, 15, 20)) // make width , height greater or equal titlelabel make.size.greaterthanorequalto(titlelabel) // make width = superview.width + 100, height = superview.height - 50 make.size.equalto(superview).sizeoffset(cgsizemake(100, -50)) // make centerx , centery = button1 make.center.equalto(button1) // make centerx = superview.centerx - 5, centery = superview.centery + 10 make.center.equalto(superview).centeroffset(cgpointmake(-5, 10))
Comments
Post a Comment