2013-03-08 101 views
0

我試圖繪製一個矩形,它應該具有的寬度5.0黑色邊框,我得到的矩形,如下圖所示,iPhone - 畫一個透明(清除)矩形邊框定製

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextStrokePath(context); 
CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.5); 
CGContextFillRect(context, rect); 

enter image description here

我能說清楚/透明(白色)背景,而不是綠色的,現在出與[UIColor whiteColor].CGColor但隨後它應該有黑色邊框也。

如何將自定義邊框設置爲矩形?

+0

白色不透明,'[UIColor clearColor]'是透明色... – Arkku 2013-03-08 14:36:42

+0

@Arkku,是的!我只是試圖讓它定製,你做到了! :) – Hemang 2013-03-08 14:51:40

回答

5

設置描邊顏色和寬度根據需要,例如:

CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 
CGContextSetLineWidth(context, 5.0f); 
CGContextStrokeRect(context, rect); 

如果您還填充矩形,這樣做填充使填充不掩飾行程。

+0

是的,它的工作!我需要在填寫完成後按照你所提到的來做。謝謝 :) – Hemang 2013-03-08 14:43:55