ios - iphone 在drawRect中使用UIGraphicsGetCurrentContext画矩形,边框外有1像素的多余?

浏览:66日期:2023-11-18

问题描述

代码如下

-(void) drawRect:(CGRect)rect{//CGContextRef context = UIGraphicsGetCurrentContext();//CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.2);[[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.2]setFill];CGRect grayRect = self.frame;UIRectFill(grayRect);CGRect cropRect = _intersectionRect;CGRect intersectionRect = CGRectIntersection(cropRect, grayRect);[[UIColor clearColor]setFill];UIRectFill(intersectionRect);}

在空白项目的Demo中,一切ok

ios - iphone 在drawRect中使用UIGraphicsGetCurrentContext画矩形,边框外有1像素的多余?

但是在我自己的项目中,有多余的1px,透明度不同的边框,请问怎么解决?ios - iphone 在drawRect中使用UIGraphicsGetCurrentContext画矩形,边框外有1像素的多余?

问题解答

回答1:

问题解决,两个rect的值应该都设置为int而不是float。

相关文章: