objective c - having trouble drawing a rectangle to the screen ios -
i following video tutorial pluralsight draws red rectangle screen. have subclass of uiview called psviewdemo has following code in .m file:
// override drawrect: if perform custom drawing. // empty implementation adversely affects performance during animation. - (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolor(context, [uicolor redcolor].cgcolor); cgcontextfillrect(context, cgrectmake(40, 400,100,200)); // drawing code }
i call in viewdidload of viewcontroller view in application (until code adds subview).
- (void)viewdidload { [super viewdidload]; psviewdemo *dv = [[psviewdemo alloc] initwithframe:cgrectmake( 0, 0, 320, 480)]; [self.view addsubview:dv]; // additional setup after loading view, typically nib. }
the whole thing compiles , runs without error there no red rectangle on screen.
what missing? pretty sure following tutorial maybe has changed in cocoa since tutorial made? i'm using xcode 5.
change
cgcontextsetfillcolor(context, [uicolor redcolor].cgcolor);
to
cgcontextsetfillcolor(context, cgcolorgetcomponents([[uicolor redcolor] cgcolor]));
Comments
Post a Comment