ios - Instantiate a DrawRect View From ViewController -


i apologize if may simple question. new using draw rect , want call viewdidload in view controller when draw rect in view subclass. have far doesn't anything. need add? thank

circleview = [[circleview alloc] init]; [self.view addsubview:circleview]; [circleview setneedsdisplay]; 

here code in circle view

- (void)drawrect:(cgrect)rect {     nslog(@"worked");     cgcontextref contextref = uigraphicsgetcurrentcontext();     cgcontextsetrgbfillcolor(contextref, 0, 0, 255, 0.1);     cgcontextsetrgbstrokecolor(contextref, 0, 0, 255, 0.5);      cgcontextstrokeellipseinrect(contextref, cgrectmake(100, 100, 25, 25));  } 

thats have. know might need init frame dont know how choose draw rect.

there no need call [circleview setneedsdisplay]; explicitly in -viewdidload, uiview automatically invoke -drawrect: when displaying first time.
circleview doesn't show because frame {0, 0; 0, 0}. need give meaningful frame, this:

circleview = [[circleview alloc] initwithframe:cgrectmake(0, 0, 200, 200)]; 

or set frame property:

circleview.frame = cgrectmake(0, 0, 200, 200); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -