0

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

shannoga
  • 19,649
  • 20
  • 104
  • 169

2 Answers2

2

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;
sch
  • 27,436
  • 3
  • 68
  • 83
0

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.

Letrstotheprez
  • 622
  • 1
  • 5
  • 11