Objective c 核心图形在一条直线上绘制带边框的矩形
如何在一条直线上画一个有边框的矩形 有不同的方法,如:Objective c 核心图形在一条直线上绘制带边框的矩形,objective-c,ios,core-graphics,Objective C,Ios,Core Graphics,如何在一条直线上画一个有边框的矩形 有不同的方法,如: CGContextStrokeRect(context, someRectangle); 及 但是,有什么东西可以同时做到这两个方面吗?CGContextDrawPath如果事先设置填充和笔划颜色,它会一次完成 CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColor(context, a); CGContextSetFillColor(co
CGContextStrokeRect(context, someRectangle);
及
但是,有什么东西可以同时做到这两个方面吗?CGContextDrawPath如果事先设置填充和笔划颜色,它会一次完成
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(context, a);
CGContextSetFillColor(context, b);
CGContextDrawPath(context, rect)
虽然,我不能说它比stroke&fill单独调用更详细…如果您只是想节省行空间,您可以定义自己的方法来进行两次调用,并将其放在实用程序类中
void strokeAndFill(CGContextRef c, CGRect rect)
{
CGContextFillRect(c, rect);
CGContextStrokeRect(c, rect);
}
隐马尔可夫模型。。。我在头文件中看到的
CGContextDrawPath
的签名是:CGContextDrawPath(CGContextRef c,CGPathDrawingMode)
Hmm。。。非常正确,我想我会单独打电话。谢谢
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef path = CGPathCreateWithRect(rect, NULL);
[[UIColor redColor] setFill];
[[UIColor greenColor] setStroke];
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFillStroke);
CGPathRelease(path);
}
void strokeAndFill(CGContextRef c, CGRect rect)
{
CGContextFillRect(c, rect);
CGContextStrokeRect(c, rect);
}