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
fillRect(10, 15, 90, 60); To fill the rectangle with a colour, we use the fillRect() method.
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)
[[UIColor colorWithWhite:29/255.f alpha:1.0] setFill];
UIRectFill(rect);
This is the simplest way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With