【发布时间】:2018-06-11 19:06:24
【问题描述】:
为了在按钮上显示进度圈,我在CGContext 中画了一条弧线,然后将其传递给UIImage,最后传递给UIButton 图像。然而,它绘制的只是一个实心正方形:
CGRect rect = CGRectMake(0, 0, myButton.frame.size.width, myButton.frame.size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 1);
[[UIColor colorWithRed:1.0 green:0. blue:0. alpha:1.0] setStroke];
[[UIColor colorWithWhite:0.9 alpha:1.0] setFill];
CGContextMoveToPoint(ctx, rect.size.width/2., rect.size.height/2.);
CGContextAddArc(ctx,
rect.size.width/2., // centerX
rect.size.height/2., // centerY
rect.size.width, // radius
0, // start Angle
M_PI/2., // end Angle
1); // clockwise
CGContextDrawPath(ctx,kCGPathFillStroke);
UIImage *progressImg=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[myButton setImage:progressImg forState:UIControlStateNormal];
为什么我得到一个实心正方形而不是一个实心的部分圆弧?这是将进度条画成圆形的最佳方式吗?
【问题讨论】:
标签: ios objective-c uibutton core-graphics cgcontext