├── .gitignore ├── CircularProgressView.h ├── CircularProgressView.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /CircularProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CircularProgressView.h 3 | // SellMyiPhone 4 | // 5 | // Created by Vincent on 1/12/17. 6 | // Copyright © 2017 zssr. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CircularProgressView : UIView 12 | /// 0 ~ 100 13 | @property (nonatomic) float progress; 14 | @end 15 | -------------------------------------------------------------------------------- /CircularProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CircularProgressView.m 3 | // SellMyiPhone 4 | // 5 | // Created by Vincent on 1/12/17. 6 | // Copyright © 2017 zssr. All rights reserved. 7 | // 8 | 9 | #import "CircularProgressView.h" 10 | 11 | 12 | #define LineWidth 5.f 13 | #define Space 7.f 14 | #define Yellow [UIColor colorWithRed:0.9725 green:0.7412 blue:0.1725 alpha:1] 15 | 16 | @implementation CircularProgressView 17 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 18 | self = [super initWithCoder:aDecoder]; 19 | if (self) { 20 | self.backgroundColor = [UIColor clearColor]; 21 | } 22 | return self; 23 | } 24 | 25 | - (void)setProgress:(float)progress { 26 | if (progress >= 100.f) { 27 | _progress = 100.f; 28 | } 29 | _progress = progress; 30 | [self setNeedsDisplay]; 31 | } 32 | 33 | - (void)drawRect:(CGRect)rect { 34 | [self drawBackground]; 35 | [self drawProgressLine]; 36 | } 37 | 38 | - (void)drawProgressLine { 39 | [self drawCircleDashed:NO]; 40 | } 41 | 42 | - (void)drawBackground { 43 | CGRect rect = self.bounds; 44 | CGPoint center = CGPointMake(CGRectGetWidth(rect) / 2.f, CGRectGetHeight(rect) / 2.f); 45 | CGFloat radius = MIN(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 - Space - LineWidth; 46 | // draw pie 47 | UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:0 endAngle:M_PI * 2 clockwise:YES]; 48 | [Yellow setFill]; 49 | [path fill]; 50 | // draw dash circle 51 | [self drawCircleDashed:YES]; 52 | } 53 | 54 | - (void)drawCircleDashed:(BOOL)dash { 55 | CGRect rect = self.bounds; 56 | CGPoint center = CGPointMake(CGRectGetWidth(rect) / 2.f, CGRectGetHeight(rect) / 2.f); 57 | CGFloat radius = MIN(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 - LineWidth / 2; 58 | CGFloat endAngle = 2 * M_PI; 59 | CGFloat startAngle = 0; 60 | if (!dash) { 61 | startAngle = -M_PI_2; 62 | endAngle = M_PI * 2 * self.progress / 100.f - M_PI_2; 63 | } 64 | UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 65 | if (dash) { 66 | CGFloat lengths[] = {2, 6}; 67 | [path setLineDash:lengths count:2 phase:0]; 68 | } 69 | [path setLineWidth:LineWidth]; 70 | [Yellow setStroke]; 71 | [path stroke]; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 煮石散人 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CircularProgressView 2 | 3 | [![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu) 4 | 5 | Circular Progress View with dash line and solid line in Objective-C 6 | 7 | 8 | 环形进度条:(虚线代表未完成进度,实线代表已完成) 9 | --------------------------------------------------------------------------------