On Mon, Mar 19, 2012 at 2:59 PM, Alex Zavatone wrote: > In the current project that I'm tasked to repair from the previous two > programmers, I've come across a load of UI elements that have been hardcoded > in place with the approach of: Just define the CGRect and we're all good. > > Nothing is laid out in an xib file and sometimes the views are hardcoded or > hardcoded relative to the rect/bounds of another view.
As Brian mentioned, this is really ok. We do a ton of layout in code and we try to follow these conventions: * Layout your views as much as possible in viewDidLoad or viewDidLayoutSubviews (iOS-5-only). * When you layout your subviews, do so given the current size of your superview. Don't hardcode your view's width to be 320 just because you are doing iPhone development and you know your subview takes up the entire width of your screen. If you know that your view should be the entire width of the superview, set the width to be the current width of the superview. * Always set appropriate autoresizing masks. In the previous example, you would most certainly want to set the subview's autoresizing mask to UIViewAutoresizingFlexibleWidth. If you also want that view to "stick" to the top of the superview you would instead set it to (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin). This is no different than what you would do in a XIB file, it is just in code, instead. - Sebastian _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com