我试图在我的UIView中绘制一个有黑色边框的透明矩形.
然而,我的代码创建了一个完全黑色的矩形.这是我的代码到目前为止
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect rectangle = CGRectMake(0,100,320,100);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context,0.0,0.5);
CGContextSetRGBstrokeColor(context,0.5);
CGContextFillRect(context,rectangle);
}
解决方法
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect rectangle = CGRectMake(0,1.0,0.0); //this is the transparent color
CGContextSetRGBstrokeColor(context,rectangle);
CGContextstrokeRect(context,rectangle); //this will draw the border
}
效果就是这样(backgroundColor是蓝色的)