Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 核心图形在一条直线上绘制带边框的矩形_Objective C_Ios_Core Graphics - Fatal编程技术网

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