標籤:radius cgpoint res layer ace path round ios enter
把一個圓環12等分(任意等分)
1 // 2 // ViewController.m 3 // twelve 4 // 5 // Created by yuency on 17/4/2. 6 // Copyright ? 2017年 yuency. All rights reserved. 7 // 8 9 #import "ViewController.h"10 11 #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)12 13 14 @interface ViewController ()15 16 @end17 18 @implementation ViewController19 20 - (void)viewDidLoad {21 [super viewDidLoad];22 23 24 //12等分, 每個環的角度是 30°, 在這個30°中再分顯示的部分和隱藏的部分25 26 #warning 修改等分數27 NSInteger equalCount = 12;28 #warning 有色地區占的比例29 CGFloat visiableProportion = .9f;30 31 32 //計算等分的角度33 CGFloat equalAngle = 360 / equalCount;34 //計算可見地區的角度35 CGFloat visiableAngle = equalAngle * visiableProportion;36 //串連成為一條曲線37 UIBezierPath *circlePath = [UIBezierPath bezierPath];38 for (int i = 0; i < 12; i ++) {39 CGFloat startAngle = (i * equalAngle);40 CGFloat endAngle = (visiableAngle + i * equalAngle);41 UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0) radius:200 / 2.f startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:YES];42 [circlePath appendPath:path];43 }44 //建立形狀45 CAShapeLayer *circleLayer = [CAShapeLayer layer];46 circleLayer.path = circlePath.CGPath;47 circleLayer.strokeColor = [UIColor magentaColor].CGColor;48 circleLayer.fillColor = [UIColor clearColor].CGColor;49 circleLayer.lineWidth = 10.0f;50 circleLayer.strokeStart = 0.0f;51 circleLayer.strokeEnd = 1.0f;52 circleLayer.position = self.view.center;53 [self.view.layer addSublayer:circleLayer];54 55 56 57 //輔助線58 UIView *vvv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 1)];59 vvv.backgroundColor = [UIColor redColor];60 vvv.center = self.view.center;61 [self.view addSubview:vvv];62 UIView *mmm = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 700)];63 mmm.backgroundColor = [UIColor redColor];64 mmm.center = self.view.center;65 [self.view addSubview:mmm];66 }67 68 69 @end
iOS-把一個圓環12等分(任意等分)