本文介绍了UIColor SetFill不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此代码中
for (int i=0;i<3;i++) {
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10);
CGContextMoveToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10);
}
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*4, self.yShift+self.rectLen*10);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*4, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*3, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*3, self.yShift+self.rectLen*10);
[[UIColor cyanColor] setFill];
[[UIColor blackColor] setStroke];
CGContextSetLineWidth(context, 1);
CGContextDrawPath(context, kCGPathStroke);
使用setFill方法的行不起作用.这可能是什么问题?代码位于drawRect:方法中
Line with setFill method doesn't work. What might be the problem of this? Code is located in drawRect: method
推荐答案
setFill不是用于Core Graphics绘图,而是用于诸如[myUIBezierPath fill]的绘图;
setFill isn't for Core Graphics drawing but for drawing like [myUIBezierPath fill];
使用以下方法设置填充颜色和描边颜色:
Instead set the fill color and stroke color using:
CGContextSetFillColorWithColor(context, [[UIColor cyanColor] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
此外,以下行:
CGContextDrawPath(context, kCGPathStroke);
由于绘制模式设置为kCGPathStoke,因此仅会 stroke 路径.要填充它,也应将其替换为
Will only stroke the path, since the drawing mode is set to kCGPathStoke. To fill it as well you should replace it with
CGContextDrawPath(context, kCGPathFillStroke);
如果路径上有孔或交叉,则应使用奇偶填充和描边
If your path has holes in it or crosses itself you should use even-odd fill and stroke
CGContextDrawPath(context, kCGPathEOFillStroke);
这篇关于UIColor SetFill不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!