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. 如何在swift中繪製弧線3
- 3. 如何在OpenGL中繪製弧線
- 4. 如何使用核心繪圖沿X軸繪製NSDate
- 5. 在覈心圖中繪製多線圖
- 6. 如何在MKMapView上使用MKOverlayView繪製圓弧/曲線線
- 7. 繪製popOver使用核心圖形
- 8. 繪製的SVG弧
- 9. 如何使用蟒蛇繪製笑臉(弧線)
- 10. 在覈心繪圖中繪製切線圖
- 11. 如何用CoreGraphics繪製橢圓弧?
- 12. 如何在java中使用繪製線繪製樓梯線?
- 13. 如何通過核心圖或核心圖形繪製Ven圖?
- 14. 如何在覈心圖形中連續繪製曲線ios
- 15. 在Android中使用SweepGradient繪製圓弧
- 16. 如何在Fabric.js中繪製圓弧
- 17. 如何通過3點繪製圓弧
- 18. 在three.js中繪製圓弧
- 19. 動態繪製弧形
- 20. 繪製弧在Java中
- 21. 繪製透明圓弧
- 22. 如何使用核心圖形繪製圖形
- 23. 如何使用核心圖中的數字繪製散點圖
- 24. 安卓繪製的圓弧與清掃弧線
- 25. 繪製圖像或繪製實心圓?
- 26. 繪製輪廓與核心圖形
- 27. 核心圖形不繪製某些行
- 28. 在CALayer中繪製核心圖形
- 29. glbegin沒有繪製在OpenGL 3.3核心
- 30. 在c中使用鼠標單擊繪製弧線#
<插入關於使用弧繪製弧的笑話> – 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