Bounds of custom UIView not correct during awakeFromNib - when are they set?

2k views Asked by At

I have a custom UIView, which I have placed using Xcode (4). I need to set some default state, based on the actual bounds of the view. During awakeFromNib, bounds seems to be returning the size of the view in the storyboard layout in Xcode.

The view is in the detail side of a UISplitViewController, which in Xcode is the size of a full portrait iPad screen, but if the app loads in landscape mode then, via springs-and-struts, its size is changed, but this appears to happen after awakeFromNib.

Should I be setting this state in some other method?

2

There are 2 answers

0
Jono On BEST ANSWER

The answer is was probably looking for, or at least the solution I have used, is to provide a public method in the UIView to be called by the parent UIViewController in viewWillAppear:

1
jrturton On

It depends what sort of state you are setting - if it is dependent on the bounds then you'll need to reset it every time the device is rotated, presumably? In that case overriding setFrame: might be a better bet - be sure to call the superclass implementation before you do anything else, though.