Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you override setFrame for a UILabel

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?

like image 337
adit Avatar asked Apr 24 '12 18:04

adit


1 Answers

You need to call [super setFrame:frame].

That will call UILabel's implementation of setFrame and not your own. That is what is causing your infinite loop.

like image 80
Heiberg Avatar answered Oct 05 '22 13:10

Heiberg