objective c - IOS - Using drawRect method to set background color on view -


im quite new ios; , made gradient etc via drawrect method, now, if want implement it, subclass view. thinking, there way can call method drawrect , make set background view, subclass of viewcontroller ?

layout this:

backgroundcolor.h

#import <uikit/uikit.h>  @interface backgroundcolor : uiview  @end 

backgroundcolor.m

#import "backgroundcolor"  @implementation backgroundcolor___fuschia   - (void)drawrect:(cgrect)rect { ... }  @end 

viewcontrollernav.h

#import <uikit/uikit.h>  @interface viewcontrollernav : uiviewcontroller  @end 

viewcontrollernav.m

@interface viewcontrollernav ()  @end  @implementation viewcontrollernav  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  @end 

i assume have import backgroundcolor , init method or ?

(ps: drawrect method uses cgrect frame = rect; need view size passed asume ?)

any apriciated

to answer original question, never call drawrect: directly. call

[self.view setneedsdisplay]; 

and system takes care of calling drawrect: @ appropriate time.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -