ios - iphone When using UIGraphicsGetCurrentContext in drawRect to draw a rectangle, is there an excess of 1 pixel outside the border?
我想大声告诉你
我想大声告诉你 2017-05-16 13:18:51
0
1
1009

code show as below

-(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);
}

In the demo of the blank project, everything is ok

But in my own project, there are extra 1px and borders with different transparency. How to solve it?

我想大声告诉你
我想大声告诉你

reply all(1)
刘奇

Problem solved, the values ​​of both rects should be set to int instead of float.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template