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

查看:148
本文介绍了ios - iphone 在drawRect中使用UIGraphicsGetCurrentContext画矩形,边框外有1像素的多余?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

代码如下

-(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

但是在我自己的项目中,有多余的1px,透明度不同的边框,请问怎么解决?

解决方案

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

这篇关于ios - iphone 在drawRect中使用UIGraphicsGetCurrentContext画矩形,边框外有1像素的多余?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆