ios - Do I really need drawRect() in custom UIView? -


i new ios , trying understand use drawrect() in custom uiviews, have simple custom view initialize code.i want update colors instance , see 2 approaches shown below. 1 should use , why?

//vcontroller customview *cv = [[customview alloc] initwithframe:...] ... [cv updatecolors];  //customview -(id) initwithframe {} -(id) initwithcoder  {} -(void) updatecolors(uicolor *color){  ----(1)   ...draw here new color ...    view1.backgroundcolor = color;    view2.backgroundcolor = color;   } - (void) drawrect{  ... draw here new color ... ---------(2)    view1.backgroundcolor = color;    view2.backgroundcolor = color;  } 

if all want change background color of view or of subviews, absolutely should not misuse drawrect: this. drawrect: when want draw view (i.e. content) when system believes needs refreshing; called @ many , unpredictable times, , don't need - need change background color, feature of view, on demand. drawrect: not place perform management of subviews.

but if are going draw view's content (e.g. view displays circle , need draw circle portray view) must use drawrect: that; only place view gets chance draw itself.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -