Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling setNeedsDisplay in layoutSubviews?

Consider a view with a custom background that is drawn in drawRect:. If the view changes size, the background need to be redrawn.

Is this a bad idea?

- (void) layoutSubviews
{
    [super layoutSubviews];
    [self setNeedsDisplay];
}

If it is, what would be a better alternative considering I can't control who changes the size of the view?

like image 705
hpique Avatar asked Dec 20 '22 13:12

hpique


1 Answers

Dont do that, it's not necessary. Set the contentMode of the view to UIViewContentModeRedraw:

UIViewContentModeRedraw

Redisplays the view when the bounds change by invoking the setNeedsDisplay method. Available in iOS 2.0 and later. Declared in UIView.h.

This will achieve the same effect.

like image 197
jrturton Avatar answered Dec 26 '22 12:12

jrturton