That's right, because it does not guarantee that initWithFrame: will be called when unpacking xib. Try using awakeFromNib or viewWillLoad or viewDidLoad . Which one you choose mainly depends on what stage of the display process you need to insert your code into.
Also, look at this question .
G Gordon Worley III
source share