我试图在我的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是蓝色的)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。