Create a complex CGRect

410 Views Asked by At

I have a view with a border of 10 pixels drawn on the method. I need to update the border color and I use [self setNeedsDisplay] to make it redraw the view. Since I need to update only the border I want to use : [self setNeedsDisplayInRect:rect] so it will draw only the border.

How can I get a rect of only the border with out the other areas of the view?

Thanks Shani

2

There are 2 best solutions below

0
sch On BEST ANSWER

You can't because a CGRect is rectangle, so it is a convex shape that can't have holes in it.

But you can decompose the border into four rectangles and call [self setNeedsDisplayInRect:rect] four times.

Also, if you import QuartzCore, you can probably use the property borderColor of the view's layer:

#import <QuartzCore/QuartzCore.h>

// ...

view.layer.borderWidth = 10;
view.layer.borderColor = [UIColor redColor].CGColor;

// And to change it later
view.layer.borderColor = [UIColor greenColor].CGColor;
0
Letrstotheprez On

You could get four CGRects around each part of the border (top, right, bottom, and left) and call the method four times with each of them.