7

I have a drawRect and I want to fill in the rect specified with a certain color. How do I do so? So far I have tried the following:

- (void)drawRect:(CGRect)rect
{
        CGContextRef context = UIGraphicsGetCurrentContext();
         CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:29/255.f alpha:1.0].CGColor);
CGContextFillRect(context, rect);
}

This doesn't seem to work

adit
  • 32,574
  • 72
  • 229
  • 373
  • 2
    See this link: http://stackoverflow.com/questions/2985359/how-to-fill-a-path-with-gradient-in-drawrect – Vishal Jan 10 '13 at 06:48
  • Also check this: http://stackoverflow.com/questions/3800278/iphone-draw-transparent-rectangle-on-uiview-to-reveal-view-beneath – Vishal Jan 10 '13 at 06:50

1 Answers1

26
[[UIColor colorWithWhite:29/255.f alpha:1.0] setFill];
UIRectFill(rect);

This is the simplest way

borrrden
  • 33,256
  • 8
  • 74
  • 109