如何在一条线上绘制带有边框的矩形?核心图形在一条线上绘制带边框的矩形
有喜欢不同的方法:
CGContextStrokeRect(context, someRectangle);
和
CGContextFillRect(context, someRectangle);
但有东西做无论是在一个?
如何在一条线上绘制带有边框的矩形?核心图形在一条线上绘制带边框的矩形
有喜欢不同的方法:
CGContextStrokeRect(context, someRectangle);
和
CGContextFillRect(context, someRectangle);
但有东西做无论是在一个?
- (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);
}
虽然,我不能说这是比任何行程&填写单独的呼叫更简洁...
如果您事先设置填充和描边颜色,CGContextDrawPath会一举成功。
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(context, a);
CGContextSetFillColor(context, b);
CGContextDrawPath(context, rect)
嗯...... CGContextDrawPath'的'我在头文件中看到签名是:'CGContextDrawPath(CGContextRef C,CGPathDrawingMode模式)' – chinabuffet
如果你只是希望节省行距,你可以定义你的自己的方法来进行两个调用并将其放置在实用程序类中。
void strokeAndFill(CGContextRef c, CGRect rect)
{
CGContextFillRect(c, rect);
CGContextStrokeRect(c, rect);
}
嗯......很真实,我只是去与单独的呼叫我想。谢谢。 – chinabuffet