I wanted to override setframe so that it centers the label as well, however doing something like:
- (void)setFrame:(CGRect)frame
{
[self setFrame:frame};
self.center = CGPointMake(self.superview.center.x, kNavigationBarFrameHeight/2);
}
gives me an infinite loop. So how do I do this?
You need to call
[super setFrame:frame].That will call UILabel’s implementation of
setFrameand not your own. That is what is causing your infinite loop.