2012-03-24 51 views
0

我有一个在该方法上绘制10像素边框的视图。 我需要更新边框颜色,我使用[self setNeedsDisplay]来使其重绘 的视图。 因为我只需要更新我想使用的边框:[self setNeedsDisplayInRect:rect]因此它只会绘制边框。创建一个复杂的CGRect

我怎样才能得到只有边界与视图的其他领域?

感谢 沙尼

回答

2

你不能因为CGRect是矩形,所以它是一个凸的形状,它不能有洞。

但是,您可以将边界分解为四个矩形,然后拨打[self setNeedsDisplayInRect:rect]四次。

另外,如果导入QuartzCore,你也许可以使用该视图的图层的属性borderColor

#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

你可以让周围的边框(上,右,下,左)的各第四部分CGRects,并与他们每个人的调用方法四倍。