iOS-把一個圓環12等分(任意等分)

來源:互聯網
上載者:User

標籤: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等分(任意等分)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.