Ash*_*wal 16 core-graphics ios
我试图在我的UIView中绘制一个带有黑色边框的透明矩形.
但我的代码创建了一个完全黑色的矩形.到目前为止,这是我的代码:
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect rectangle = CGRectMake(0, 100, 320, 100);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.5);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.5);
CGContextFillRect(context, rectangle);
}
Run Code Online (Sandbox Code Playgroud)
Guo*_*uan 21
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect rectangle = CGRectMake(0, 100, 320, 100);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0); //this is the transparent color
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.5);
CGContextFillRect(context, rectangle);
CGContextStrokeRect(context, rectangle); //this will draw the border
}
Run Code Online (Sandbox Code Playgroud)
效果是这样的(backgroundColor是蓝色的)

| 归档时间: |
|
| 查看次数: |
38781 次 |
| 最近记录: |