CoreGraphics FillPath和描边路径 [英] CoreGraphics FillPath And Stroke Path

查看:89
本文介绍了CoreGraphics FillPath和描边路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制一个六边形,并用以Image作为图案的颜色填充它。
我这样做了:

I need to draw an hexagon and fill it with a color build with an Image as pattern. I did:

CGContextSaveGState(context);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:[UIImage imageNamed:@"patternerba.png"]] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(context, 3.0);
// drawing hexagon here...
CGContextStrokePath(context);
CGContextFillPath(context);
[[NSString stringWithFormat:@"Foo"] drawAtPoint:innerRect.origin withFont:[UIFont fontWithName:@"Helvetica" size:16]];
CGContextRestoreGState(context);

但是根据CGContextStrokePath和CGContextFillPath的顺序,我得到了一个带边框的六边形,但是没有填充或填充,但是没有边界。我该如何解决?

But depending from the order of CGContextStrokePath and CGContextFillPath, I get an hexagon bordered but not filled or filled but not bordered. How can I fix this?

推荐答案

尝试

CGContextDrawPath(context, kCGPathFillStroke);

而不是

CGContextStrokePath(context);
CGContextFillPath(context);

这篇关于CoreGraphics FillPath和描边路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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