Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I fill in drawRect with color

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

like image 911
adit Avatar asked Jan 10 '13 06:01

adit


People also ask

How do you fill a rectangle with color in Java?

fillRect(10, 15, 90, 60); To fill the rectangle with a colour, we use the fillRect() method.

How do you make a drawRect in Java?

In Java, to draw a rectangle (outlines) onto the current graphics context, we can use the following methods provided by the Graphics/Graphics2D class: drawRect(int x, int y, int width, int height) draw3DRect(int x, int y, int width, int height, boolean raised) draw(Rectangle2D)


1 Answers

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

This is the simplest way

like image 184
borrrden Avatar answered Sep 29 '22 12:09

borrrden