我建议用圆弧(实际上是一系列半圆)来代替圆角矩形。例如,考虑一个部分是三个独立的半圆:
然后,您可以借鉴这些弧像这样:
CGContextAddArc(context, center.x, center.y - side/4.0, side/4.0, M_PI_2, -M_PI_2, TRUE); // red part
CGContextAddArc(context, center.x, center.y + side/4.0, side/4.0, M_PI_2, -M_PI_2, NO); // blue part
CGContextAddArc(context, center.x, center.y, side/2.0, -M_PI_2, M_PI_2, YES); // dark grey stroke
但很明显,你可能不会实际绘制这些笔画,而是只需填写他们,然后重复这个过程符号的底部部分
- (void)drawRect:(CGRect)rect {
CGFloat side = MIN(rect.size.width, rect.size.height); // length of the side of the square in which the symbol will rest
CGPoint center = CGPointMake(rect.size.width/2.0, rect.size.height/2.0); // the center of that square
CGContextRef context = UIGraphicsGetCurrentContext();
// draw white part
CGContextAddArc(context, center.x, center.y - side/4.0, side/4.0, M_PI_2, -M_PI_2, TRUE);
CGContextAddArc(context, center.x, center.y + side/4.0, side/4.0, M_PI_2, -M_PI_2, NO);
CGContextAddArc(context, center.x, center.y, side/2.0, -M_PI_2, M_PI_2, YES);
CGContextClosePath(context);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillPath(context);
// draw black part
CGContextAddArc(context, center.x, center.y - side/4.0, side/4.0, M_PI_2, -M_PI_2, TRUE);
CGContextAddArc(context, center.x, center.y + side/4.0, side/4.0, M_PI_2, -M_PI_2, NO);
CGContextAddArc(context, center.x, center.y, side/2.0, -M_PI_2, M_PI_2, NO);
CGContextClosePath(context);
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextFillPath(context);
// draw black dot
CGContextAddArc(context, center.x, center.y - side/4.0, side/12.0, 0, M_PI * 2.0, YES);
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextFillPath(context);
// draw white dot
CGContextAddArc(context, center.x, center.y + side/4.0, side/12.0, 0, M_PI * 2.0, YES);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillPath(context);
}
国债收益率:
谢谢!这工作完美。我一直在做错事。 – Cory 2014-09-30 19:04:03