Call setNeedsDisplay in layoutSubviews?

Consider a view with a custom background drawn in drawRect: If the view is resized, the background needs to be redrawn.

It is a bad idea?

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

If so, would that be a better alternative, given that I cannot control who resizes the view?

+4
source share
1 answer

Do not do this, this is not necessary. Set the contentMode parameter to the contentMode view:

UIViewContentModeRedraw

Re-displays the view when the borders change by calling the setNeedsDisplay method. Available in iOS 2.0 and later. Announced in UIView.h.

This will lead to the same effect.

+10
source

Source: https://habr.com/ru/post/1446690/


All Articles