Was just wondering how you all go about centering a subview in the viewcontrollers main view while in loadView. I know the code for how to center it, but the problem is, while in loadView, the viewcontrollers main view frame is incorrect since it hasn’t resized it yet to fit in between my tabbar and navbar. So if I center a subview within it, it won’t be centered by the time the view appears. I did a little experimenting and it seems the viewcontrollers view sets its frame correctly somewhere after viewWillAppear is called and before viewDidAppear is called. Anyone have any insight on how I can accomplish this correctly while in loadView? (overriding layoutSubviews isn’t an option)
Was just wondering how you all go about centering a subview in the viewcontrollers
Share
If you want to keep the subview always at the center, you should set the correct frame of your subview in either
-viewDidLoador-loadView, after theviewproperty is correctly set, and set itsautoresizingMaskproperty toUIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin.Also remember to set your superview’s
autoresizesSubviewstoYES, either from xib or your initialization code.