0
A
回答
1
上面的图片只是两个圆圈 - 一个是在另一个圆孔中切割。这与您想要完成的目标并不相近。您需要使用CGContextAddArc
。
做这样的事情:向内
- 打开路径
- 移动到一个点
- 开始绘制弧
CGContextAddArc
- 移动(和画线),以圆弧中心切片的所需宽度
- 绘制反向弧
- 关闭路径
0
使用中间点算法,如果你想画圈圈,使同心圆你的社交圈半径提供差异
0
我中有你想要的东西:
// CircularProgress.h
#import <UIKit/UIKit.h>
@interface CircularProgress : UIView
@property (nonatomic, assign) CGFloat percent;
@end
// CircularProgress.m
#import "CircularProgress.h"
@implementation CircularProgress
- (void)setPercent:(CGFloat)percent
{
_percent = percent;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bounds = [self bounds];
CGPoint center = CGPointMake(bounds.size.width/2.0, bounds.size.height/2.0);
CGFloat lineWidth = 8.0;
CGFloat innerRadius = (bounds.size.width/2.0) - lineWidth;
CGFloat outerRadius = innerRadius + lineWidth;
CGFloat startAngle = -((float)M_PI/2.0);
CGFloat endAngle = ((self.percent/100.0) * 2 * (float)M_PI) + startAngle;
UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath];
processBackgroundPath.lineWidth = lineWidth;
CGFloat radius = (self.bounds.size.width - lineWidth)/2.0;
CGFloat fullAngle = (2.0 * (float)M_PI) + startAngle;
[processBackgroundPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:fullAngle clockwise:YES];
[[UIColor whiteColor] set];
[processBackgroundPath stroke];
CGMutablePathRef progressPath = CGPathCreateMutable();
CGPathMoveToPoint(progressPath, NULL, center.x, center.y - innerRadius);
CGPathAddArc(progressPath, NULL, center.x, center.y, innerRadius, startAngle, endAngle, YES);
CGPathAddArc(progressPath, NULL, center.x, center.y, outerRadius, endAngle, startAngle, NO);
CGPathCloseSubpath(progressPath);
UIColor *aColor = [UIColor colorWithRed:0.941 green:0.776 blue:0.216 alpha:1.0];
[aColor setFill];
CGContextAddPath(context, progressPath);
CGContextFillPath(context);
CGPathRelease(progressPath);
}
@end
你只需要创建CircularProgress
所需大小的类(它应该是正方形)的对象,并将其作为子视图添加到您的主视图。然后只需更改percent
值并享受结果。颜色和宽度现在被硬编码,因为它不是完成的控件,但你应该抓住这个想法。
相关问题
- 1. Silverlight - 如何绘制弧线?
- 2. 弧线,KineticJS绘制
- 3. 如何用Qt绘制弧线?
- 4. 使用核心图形绘制浮雕圆弧
- 5. 在Silverlight中绘制弧线
- 6. 绘制弧线cocos2d-html5
- 7. 如何在vml中绘制弧线
- 8. 如何仅绘制这部分弧线?
- 9. 如何在swift中绘制弧线3
- 10. 如何在OpenGL中绘制弧线
- 11. Cocos2d v3:你如何绘制弧线?
- 12. 如何使用核心绘图沿X轴绘制NSDate
- 13. 如何绘制2D弧
- 14. 在核心图中绘制多线图
- 15. 用Core Graphics绘制圆弧时绘制的额外线条
- 16. 如何在MKMapView上使用MKOverlayView绘制圆弧/曲线线
- 17. 绘制popOver使用核心图形
- 18. 绘制的SVG弧
- 19. 在核心绘图中绘制切线图
- 20. 如何使用蟒蛇绘制笑脸(弧线)
- 21. 如何绘制使用SVG元素的90度弧线?
- 22. 如何在createjs中使用弧线绘制圆形?
- 23. excanvas中的绘制弧IE8到2Pi不绘制弧
- 24. 如何用CoreGraphics绘制椭圆弧?
- 25. Java如何使用绘制弧和连接到另一条弧
- 26. 使用点向中心绘制线条
- 27. 绘制半径增加的弧线?
- 28. 如何通过核心图或核心图形绘制Ven图?
- 29. 在不使用核心绘图库的情况下绘制折线图
- 30. 在ios上使用核心绘图在一条线上绘制不同颜色
<插入关于使用弧绘制弧的笑话> – Fonix 2013-05-08 07:37:11
看看这篇文章http://www.raywenderlich.com/33193/core-graphics-tutorial-arcs-and-paths – tkanzakic 2013-05-08 08:04:42