iphone - 画分成相等部分的空心圆

标签 iphone ios uibezierpath

我想画一个如下图的空心圆

我得到了下面的代码片段来绘制空心圆

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor whiteColor];

        // Determine our start and stop angles for the arc (in radians)
        startAngle = M_PI * 1.5;
        endAngle = startAngle + (M_PI * 2);

    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    // Display our percentage as a string
    NSString* textContent = [NSString stringWithFormat:@"%d", self.percent];

    UIBezierPath* bezierPath = [UIBezierPath bezierPath];

    // Create our arc, with the correct angles
    [bezierPath addArcWithCenter:CGPointMake(rect.size.width / 2, rect.size.height / 2)
                          radius:130
                      startAngle:startAngle
                        endAngle:(endAngle - startAngle) * (_percent / 100.0) + startAngle
                       clockwise:YES];


    // Set the display for the path, and stroke it
    bezierPath.lineWidth = 50;
    [[UIColor redColor] setStroke];
    [bezierPath stroke];

    // Text Drawing
    CGRect textRect = CGRectMake((rect.size.width / 2.0) - 71/2.0, (rect.size.height / 2.0) - 45/2.0, 71, 45);
    [[UIColor blackColor] setFill];
    [textContent drawInRect: textRect withFont: [UIFont fontWithName: @"Helvetica-Bold" size: 42.5] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentCenter];
}

我也需要空心线中的分隔线,如上图所示。任何建议都会有所帮助....

最佳答案

看一看HKCircularProgressView
我正在将其用于我自己的项目,可以轻松满足您的需求扩展功能。

关于iphone - 画分成相等部分的空心圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16788919/

相关文章:

android - React Native - 如果应用程序 Y 已安装,应用程序 X 如何打开应用程序 Y

iphone - 在 iPad 上运行 Ruby 解释器

objective-c - 如何从 UIBezierPath 生成 CGPoint 数组(沿给定路径触摸滑动对象)

ios - Braintree v.zero iOS SDK 是否支持自适应支付?

iphone - 在UIImagePickerController中,是否可以获取UIImagePickerControllerMediaURL的NSURL值?

iphone - objectForKey,iOS 中的 JSON?不工作!

iphone - 在更新到iOS 6之后,所有“取消”按钮都无法在sharekit中使用

swift - 每个 UIGraphicsGetCurrentContext 不同的 setStroke 颜色

ios - 如何在 UIView 中独立绘制到 CAShapeLayer?

iphone - 游戏中心同转