chi*_*fet 6 core-graphics objective-c ios
如何在一行中绘制带边框的矩形?
有单独的方法,如:
CGContextStrokeRect(context, someRectangle);
Run Code Online (Sandbox Code Playgroud)
和
CGContextFillRect(context, someRectangle);
Run Code Online (Sandbox Code Playgroud)
但有什么东西可以同时做到吗?
- (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);
}
Run Code Online (Sandbox Code Playgroud)
虽然,我不能说它比中风更简洁,并填写单独的电话......
如果您只是想节省行空间,可以定义自己的方法来进行两次调用并将其放在实用程序类中.
void strokeAndFill(CGContextRef c, CGRect rect)
{
CGContextFillRect(c, rect);
CGContextStrokeRect(c, rect);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14570 次 |
| 最近记录: |