├── .gitignore ├── CircularProgressExample ├── CircularProgressExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── CircularProgressExample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── CircularColor+Tale.swift │ ├── Info.plist │ ├── SceneDelegate.swift │ └── ViewController.swift ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── CircularProgress │ ├── CircularAnimation.swift │ ├── CircularColor.swift │ ├── CircularProgressConfiguration.swift │ ├── CircularProgressItem.swift │ ├── CircularProgressLayer.swift │ ├── CircularProgressStackView.swift │ ├── CircularProgressView.swift │ └── CircularShape.swift └── Tests └── CircularProgressTests └── CircularProgressTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/macos,xcode,swift 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,xcode,swift 4 | 5 | ### macOS ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | ### Swift ### 34 | # Xcode 35 | # 36 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 37 | 38 | ## User settings 39 | xcuserdata/ 40 | 41 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 42 | *.xcscmblueprint 43 | *.xccheckout 44 | 45 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 46 | build/ 47 | DerivedData/ 48 | *.moved-aside 49 | *.pbxuser 50 | !default.pbxuser 51 | *.mode1v3 52 | !default.mode1v3 53 | *.mode2v3 54 | !default.mode2v3 55 | *.perspectivev3 56 | !default.perspectivev3 57 | 58 | ## Obj-C/Swift specific 59 | *.hmap 60 | 61 | ## App packaging 62 | *.ipa 63 | *.dSYM.zip 64 | *.dSYM 65 | 66 | ## Playgrounds 67 | timeline.xctimeline 68 | playground.xcworkspace 69 | 70 | # Swift Package Manager 71 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 72 | # Packages/ 73 | # Package.pins 74 | # Package.resolved 75 | # *.xcodeproj 76 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 77 | # hence it is not needed unless you have added a package configuration file to your project 78 | # .swiftpm 79 | 80 | .build/ 81 | 82 | # CocoaPods 83 | # We recommend against adding the Pods directory to your .gitignore. However 84 | # you should judge for yourself, the pros and cons are mentioned at: 85 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 86 | # Pods/ 87 | # Add this line if you want to avoid checking in source code from the Xcode workspace 88 | # *.xcworkspace 89 | 90 | # Carthage 91 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 92 | # Carthage/Checkouts 93 | 94 | Carthage/Build/ 95 | 96 | # Accio dependency management 97 | Dependencies/ 98 | .accio/ 99 | 100 | # fastlane 101 | # It is recommended to not store the screenshots in the git repo. 102 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 103 | # For more information about the recommended setup visit: 104 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 105 | 106 | fastlane/report.xml 107 | fastlane/Preview.html 108 | fastlane/screenshots/**/*.png 109 | fastlane/test_output 110 | 111 | # Code Injection 112 | # After new code Injection tools there's a generated folder /iOSInjectionProject 113 | # https://github.com/johnno1962/injectionforxcode 114 | 115 | iOSInjectionProject/ 116 | 117 | ### Xcode ### 118 | 119 | ## Xcode 8 and earlier 120 | 121 | ### Xcode Patch ### 122 | *.xcodeproj/* 123 | !*.xcodeproj/project.pbxproj 124 | !*.xcodeproj/xcshareddata/ 125 | !*.xcworkspace/contents.xcworkspacedata 126 | /*.gcno 127 | **/xcshareddata/WorkspaceSettings.xcsettings 128 | 129 | # End of https://www.toptal.com/developers/gitignore/api/macos,xcode,swift 130 | 131 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CC8CD5CC27F6F4CD0094AC3A /* CircularProgress in Frameworks */ = {isa = PBXBuildFile; productRef = CC8CD5CB27F6F4CD0094AC3A /* CircularProgress */; }; 11 | CCB6E25F27F6CA0C0097A1CF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCB6E25E27F6CA0C0097A1CF /* AppDelegate.swift */; }; 12 | CCB6E26127F6CA0C0097A1CF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCB6E26027F6CA0C0097A1CF /* SceneDelegate.swift */; }; 13 | CCB6E26327F6CA0C0097A1CF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCB6E26227F6CA0C0097A1CF /* ViewController.swift */; }; 14 | CCB6E26627F6CA0C0097A1CF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CCB6E26427F6CA0C0097A1CF /* Main.storyboard */; }; 15 | CCB6E26827F6CA0F0097A1CF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CCB6E26727F6CA0F0097A1CF /* Assets.xcassets */; }; 16 | CCB6E26B27F6CA0F0097A1CF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CCB6E26927F6CA0F0097A1CF /* LaunchScreen.storyboard */; }; 17 | CCB6E28227F6CA220097A1CF /* CircularColor+Tale.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCB6E27927F6CA220097A1CF /* CircularColor+Tale.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | CC8CD5C927F6F4100094AC3A /* CircularProgress */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = CircularProgress; path = ..; sourceTree = ""; }; 22 | CCB6E25B27F6CA0C0097A1CF /* CircularProgressExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CircularProgressExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | CCB6E25E27F6CA0C0097A1CF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | CCB6E26027F6CA0C0097A1CF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 25 | CCB6E26227F6CA0C0097A1CF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | CCB6E26527F6CA0C0097A1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | CCB6E26727F6CA0F0097A1CF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | CCB6E26A27F6CA0F0097A1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | CCB6E26C27F6CA0F0097A1CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | CCB6E27927F6CA220097A1CF /* CircularColor+Tale.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CircularColor+Tale.swift"; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | CCB6E25827F6CA0C0097A1CF /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | CC8CD5CC27F6F4CD0094AC3A /* CircularProgress in Frameworks */, 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | CC8CD5C827F6F4100094AC3A /* Packages */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | CC8CD5C927F6F4100094AC3A /* CircularProgress */, 49 | ); 50 | name = Packages; 51 | sourceTree = ""; 52 | }; 53 | CC8CD5CA27F6F4CD0094AC3A /* Frameworks */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | ); 57 | name = Frameworks; 58 | sourceTree = ""; 59 | }; 60 | CCB6E25227F6CA0C0097A1CF = { 61 | isa = PBXGroup; 62 | children = ( 63 | CC8CD5C827F6F4100094AC3A /* Packages */, 64 | CCB6E25D27F6CA0C0097A1CF /* CircularProgressExample */, 65 | CCB6E25C27F6CA0C0097A1CF /* Products */, 66 | CC8CD5CA27F6F4CD0094AC3A /* Frameworks */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | CCB6E25C27F6CA0C0097A1CF /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | CCB6E25B27F6CA0C0097A1CF /* CircularProgressExample.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | CCB6E25D27F6CA0C0097A1CF /* CircularProgressExample */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | CCB6E25E27F6CA0C0097A1CF /* AppDelegate.swift */, 82 | CCB6E26027F6CA0C0097A1CF /* SceneDelegate.swift */, 83 | CCB6E26227F6CA0C0097A1CF /* ViewController.swift */, 84 | CCB6E27927F6CA220097A1CF /* CircularColor+Tale.swift */, 85 | CCB6E26427F6CA0C0097A1CF /* Main.storyboard */, 86 | CCB6E26727F6CA0F0097A1CF /* Assets.xcassets */, 87 | CCB6E26927F6CA0F0097A1CF /* LaunchScreen.storyboard */, 88 | CCB6E26C27F6CA0F0097A1CF /* Info.plist */, 89 | ); 90 | path = CircularProgressExample; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | CCB6E25A27F6CA0C0097A1CF /* CircularProgressExample */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = CCB6E26F27F6CA0F0097A1CF /* Build configuration list for PBXNativeTarget "CircularProgressExample" */; 99 | buildPhases = ( 100 | CCB6E25727F6CA0C0097A1CF /* Sources */, 101 | CCB6E25827F6CA0C0097A1CF /* Frameworks */, 102 | CCB6E25927F6CA0C0097A1CF /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | ); 108 | name = CircularProgressExample; 109 | packageProductDependencies = ( 110 | CC8CD5CB27F6F4CD0094AC3A /* CircularProgress */, 111 | ); 112 | productName = CircularProgressExample; 113 | productReference = CCB6E25B27F6CA0C0097A1CF /* CircularProgressExample.app */; 114 | productType = "com.apple.product-type.application"; 115 | }; 116 | /* End PBXNativeTarget section */ 117 | 118 | /* Begin PBXProject section */ 119 | CCB6E25327F6CA0C0097A1CF /* Project object */ = { 120 | isa = PBXProject; 121 | attributes = { 122 | BuildIndependentTargetsInParallel = 1; 123 | LastSwiftUpdateCheck = 1320; 124 | LastUpgradeCheck = 1320; 125 | TargetAttributes = { 126 | CCB6E25A27F6CA0C0097A1CF = { 127 | CreatedOnToolsVersion = 13.2.1; 128 | }; 129 | }; 130 | }; 131 | buildConfigurationList = CCB6E25627F6CA0C0097A1CF /* Build configuration list for PBXProject "CircularProgressExample" */; 132 | compatibilityVersion = "Xcode 13.0"; 133 | developmentRegion = en; 134 | hasScannedForEncodings = 0; 135 | knownRegions = ( 136 | en, 137 | Base, 138 | ); 139 | mainGroup = CCB6E25227F6CA0C0097A1CF; 140 | productRefGroup = CCB6E25C27F6CA0C0097A1CF /* Products */; 141 | projectDirPath = ""; 142 | projectRoot = ""; 143 | targets = ( 144 | CCB6E25A27F6CA0C0097A1CF /* CircularProgressExample */, 145 | ); 146 | }; 147 | /* End PBXProject section */ 148 | 149 | /* Begin PBXResourcesBuildPhase section */ 150 | CCB6E25927F6CA0C0097A1CF /* Resources */ = { 151 | isa = PBXResourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | CCB6E26B27F6CA0F0097A1CF /* LaunchScreen.storyboard in Resources */, 155 | CCB6E26827F6CA0F0097A1CF /* Assets.xcassets in Resources */, 156 | CCB6E26627F6CA0C0097A1CF /* Main.storyboard in Resources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXResourcesBuildPhase section */ 161 | 162 | /* Begin PBXSourcesBuildPhase section */ 163 | CCB6E25727F6CA0C0097A1CF /* Sources */ = { 164 | isa = PBXSourcesBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | CCB6E28227F6CA220097A1CF /* CircularColor+Tale.swift in Sources */, 168 | CCB6E26327F6CA0C0097A1CF /* ViewController.swift in Sources */, 169 | CCB6E25F27F6CA0C0097A1CF /* AppDelegate.swift in Sources */, 170 | CCB6E26127F6CA0C0097A1CF /* SceneDelegate.swift in Sources */, 171 | ); 172 | runOnlyForDeploymentPostprocessing = 0; 173 | }; 174 | /* End PBXSourcesBuildPhase section */ 175 | 176 | /* Begin PBXVariantGroup section */ 177 | CCB6E26427F6CA0C0097A1CF /* Main.storyboard */ = { 178 | isa = PBXVariantGroup; 179 | children = ( 180 | CCB6E26527F6CA0C0097A1CF /* Base */, 181 | ); 182 | name = Main.storyboard; 183 | sourceTree = ""; 184 | }; 185 | CCB6E26927F6CA0F0097A1CF /* LaunchScreen.storyboard */ = { 186 | isa = PBXVariantGroup; 187 | children = ( 188 | CCB6E26A27F6CA0F0097A1CF /* Base */, 189 | ); 190 | name = LaunchScreen.storyboard; 191 | sourceTree = ""; 192 | }; 193 | /* End PBXVariantGroup section */ 194 | 195 | /* Begin XCBuildConfiguration section */ 196 | CCB6E26D27F6CA0F0097A1CF /* Debug */ = { 197 | isa = XCBuildConfiguration; 198 | buildSettings = { 199 | ALWAYS_SEARCH_USER_PATHS = NO; 200 | CLANG_ANALYZER_NONNULL = YES; 201 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 202 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 203 | CLANG_CXX_LIBRARY = "libc++"; 204 | CLANG_ENABLE_MODULES = YES; 205 | CLANG_ENABLE_OBJC_ARC = YES; 206 | CLANG_ENABLE_OBJC_WEAK = YES; 207 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 208 | CLANG_WARN_BOOL_CONVERSION = YES; 209 | CLANG_WARN_COMMA = YES; 210 | CLANG_WARN_CONSTANT_CONVERSION = YES; 211 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 212 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 213 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 214 | CLANG_WARN_EMPTY_BODY = YES; 215 | CLANG_WARN_ENUM_CONVERSION = YES; 216 | CLANG_WARN_INFINITE_RECURSION = YES; 217 | CLANG_WARN_INT_CONVERSION = YES; 218 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 220 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 221 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 222 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 223 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 224 | CLANG_WARN_STRICT_PROTOTYPES = YES; 225 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 226 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 227 | CLANG_WARN_UNREACHABLE_CODE = YES; 228 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 229 | COPY_PHASE_STRIP = NO; 230 | DEBUG_INFORMATION_FORMAT = dwarf; 231 | ENABLE_STRICT_OBJC_MSGSEND = YES; 232 | ENABLE_TESTABILITY = YES; 233 | GCC_C_LANGUAGE_STANDARD = gnu11; 234 | GCC_DYNAMIC_NO_PIC = NO; 235 | GCC_NO_COMMON_BLOCKS = YES; 236 | GCC_OPTIMIZATION_LEVEL = 0; 237 | GCC_PREPROCESSOR_DEFINITIONS = ( 238 | "DEBUG=1", 239 | "$(inherited)", 240 | ); 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 248 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 249 | MTL_FAST_MATH = YES; 250 | ONLY_ACTIVE_ARCH = YES; 251 | SDKROOT = iphoneos; 252 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 253 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 254 | }; 255 | name = Debug; 256 | }; 257 | CCB6E26E27F6CA0F0097A1CF /* Release */ = { 258 | isa = XCBuildConfiguration; 259 | buildSettings = { 260 | ALWAYS_SEARCH_USER_PATHS = NO; 261 | CLANG_ANALYZER_NONNULL = YES; 262 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_ENABLE_OBJC_WEAK = YES; 268 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 269 | CLANG_WARN_BOOL_CONVERSION = YES; 270 | CLANG_WARN_COMMA = YES; 271 | CLANG_WARN_CONSTANT_CONVERSION = YES; 272 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 273 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 274 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 275 | CLANG_WARN_EMPTY_BODY = YES; 276 | CLANG_WARN_ENUM_CONVERSION = YES; 277 | CLANG_WARN_INFINITE_RECURSION = YES; 278 | CLANG_WARN_INT_CONVERSION = YES; 279 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 280 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 281 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 285 | CLANG_WARN_STRICT_PROTOTYPES = YES; 286 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 287 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 288 | CLANG_WARN_UNREACHABLE_CODE = YES; 289 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 290 | COPY_PHASE_STRIP = NO; 291 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 292 | ENABLE_NS_ASSERTIONS = NO; 293 | ENABLE_STRICT_OBJC_MSGSEND = YES; 294 | GCC_C_LANGUAGE_STANDARD = gnu11; 295 | GCC_NO_COMMON_BLOCKS = YES; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 298 | GCC_WARN_UNDECLARED_SELECTOR = YES; 299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 300 | GCC_WARN_UNUSED_FUNCTION = YES; 301 | GCC_WARN_UNUSED_VARIABLE = YES; 302 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 303 | MTL_ENABLE_DEBUG_INFO = NO; 304 | MTL_FAST_MATH = YES; 305 | SDKROOT = iphoneos; 306 | SWIFT_COMPILATION_MODE = wholemodule; 307 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 308 | VALIDATE_PRODUCT = YES; 309 | }; 310 | name = Release; 311 | }; 312 | CCB6E27027F6CA0F0097A1CF /* Debug */ = { 313 | isa = XCBuildConfiguration; 314 | buildSettings = { 315 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 316 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 317 | CODE_SIGN_STYLE = Automatic; 318 | CURRENT_PROJECT_VERSION = 1; 319 | DEVELOPMENT_TEAM = GXZ23M5TP2; 320 | GENERATE_INFOPLIST_FILE = YES; 321 | INFOPLIST_FILE = CircularProgressExample/Info.plist; 322 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 323 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 324 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 325 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 326 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 327 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 328 | LD_RUNPATH_SEARCH_PATHS = ( 329 | "$(inherited)", 330 | "@executable_path/Frameworks", 331 | ); 332 | MARKETING_VERSION = 1.0; 333 | PRODUCT_BUNDLE_IDENTIFIER = com.82flex.CircularProgressExample; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | SWIFT_EMIT_LOC_STRINGS = YES; 336 | SWIFT_VERSION = 5.0; 337 | TARGETED_DEVICE_FAMILY = "1,2"; 338 | }; 339 | name = Debug; 340 | }; 341 | CCB6E27127F6CA0F0097A1CF /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 346 | CODE_SIGN_STYLE = Automatic; 347 | CURRENT_PROJECT_VERSION = 1; 348 | DEVELOPMENT_TEAM = GXZ23M5TP2; 349 | GENERATE_INFOPLIST_FILE = YES; 350 | INFOPLIST_FILE = CircularProgressExample/Info.plist; 351 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 352 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 353 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 354 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 355 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 356 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 357 | LD_RUNPATH_SEARCH_PATHS = ( 358 | "$(inherited)", 359 | "@executable_path/Frameworks", 360 | ); 361 | MARKETING_VERSION = 1.0; 362 | PRODUCT_BUNDLE_IDENTIFIER = com.82flex.CircularProgressExample; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | SWIFT_EMIT_LOC_STRINGS = YES; 365 | SWIFT_VERSION = 5.0; 366 | TARGETED_DEVICE_FAMILY = "1,2"; 367 | }; 368 | name = Release; 369 | }; 370 | /* End XCBuildConfiguration section */ 371 | 372 | /* Begin XCConfigurationList section */ 373 | CCB6E25627F6CA0C0097A1CF /* Build configuration list for PBXProject "CircularProgressExample" */ = { 374 | isa = XCConfigurationList; 375 | buildConfigurations = ( 376 | CCB6E26D27F6CA0F0097A1CF /* Debug */, 377 | CCB6E26E27F6CA0F0097A1CF /* Release */, 378 | ); 379 | defaultConfigurationIsVisible = 0; 380 | defaultConfigurationName = Release; 381 | }; 382 | CCB6E26F27F6CA0F0097A1CF /* Build configuration list for PBXNativeTarget "CircularProgressExample" */ = { 383 | isa = XCConfigurationList; 384 | buildConfigurations = ( 385 | CCB6E27027F6CA0F0097A1CF /* Debug */, 386 | CCB6E27127F6CA0F0097A1CF /* Release */, 387 | ); 388 | defaultConfigurationIsVisible = 0; 389 | defaultConfigurationName = Release; 390 | }; 391 | /* End XCConfigurationList section */ 392 | 393 | /* Begin XCSwiftPackageProductDependency section */ 394 | CC8CD5CB27F6F4CD0094AC3A /* CircularProgress */ = { 395 | isa = XCSwiftPackageProductDependency; 396 | productName = CircularProgress; 397 | }; 398 | /* End XCSwiftPackageProductDependency section */ 399 | }; 400 | rootObject = CCB6E25327F6CA0C0097A1CF /* Project object */; 401 | } 402 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CircularProgressExample 4 | // 5 | // Created by Rachel on 4/1/22. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/CircularColor+Tale.swift: -------------------------------------------------------------------------------- 1 | import CircularProgress 2 | 3 | public extension CircularColor { 4 | 5 | static let taleRed = CircularColor(hexString: "#E27161") 6 | 7 | static let taleGreen = CircularColor(hexString: "#4DB6AC") 8 | 9 | static let taleBlue = CircularColor(hexString: "#5291C3") 10 | 11 | static let taleSecondaryRed = CircularColor(hexString: "#FBDEDE") 12 | 13 | static let taleSecondaryGreen = CircularColor(hexString: "#DBF0EE") 14 | 15 | static let taleSecondaryBlue = CircularColor(hexString: "#DBE9F2") 16 | } 17 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIApplicationSceneManifest 6 | 7 | UIApplicationSupportsMultipleScenes 8 | 9 | UISceneConfigurations 10 | 11 | UIWindowSceneSessionRoleApplication 12 | 13 | 14 | UISceneConfigurationName 15 | Default Configuration 16 | UISceneDelegateClassName 17 | $(PRODUCT_MODULE_NAME).SceneDelegate 18 | UISceneStoryboardFile 19 | Main 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // CircularProgressExample 4 | // 5 | // Created by Rachel on 4/1/22. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /CircularProgressExample/CircularProgressExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CircularProgressExample 4 | // 5 | // Created by Rachel on 4/1/22. 6 | // 7 | 8 | import UIKit 9 | import CircularProgress 10 | 11 | class ViewController: UIViewController { 12 | 13 | private var stackView: CircularProgressStackView! 14 | 15 | override func loadView() { 16 | let view = UIView() 17 | view.backgroundColor = .white 18 | 19 | let stackView = CircularProgressStackView() 20 | stackView.spacing = 6 21 | 22 | let redProgressView = CircularProgressView( 23 | lineWidth: 24, 24 | fillColor: CircularColor.taleRed, 25 | backgroundColor: CircularColor.taleSecondaryRed 26 | ) 27 | redProgressView.progressItem.progress = 0.75 28 | 29 | let greenProgressView = CircularProgressView( 30 | lineWidth: 24, 31 | fillColor: CircularColor.taleGreen, 32 | backgroundColor: CircularColor.taleSecondaryGreen 33 | ) 34 | greenProgressView.progressItem.progress = 0.7 35 | 36 | let blueProgressView = CircularProgressView( 37 | lineWidth: 24, 38 | fillColor: CircularColor.taleBlue, 39 | backgroundColor: CircularColor.taleSecondaryBlue 40 | ) 41 | blueProgressView.progressItem.progress = 0.65 42 | 43 | stackView.addSubview(redProgressView) 44 | stackView.addSubview(greenProgressView) 45 | stackView.addSubview(blueProgressView) 46 | 47 | self.stackView = stackView 48 | 49 | view.addSubview(stackView) 50 | self.view = view 51 | 52 | let tapGesture = UITapGestureRecognizer(target: self, action: #selector(viewTapped(_:))) 53 | view.addGestureRecognizer(tapGesture) 54 | } 55 | 56 | private var lastViewTappedAt: TimeInterval = 0 57 | @objc func viewTapped(_ sender: UITapGestureRecognizer) { 58 | let current = Date().timeIntervalSinceReferenceDate 59 | if current - lastViewTappedAt > 0.75 { 60 | stackView.managedSubviews.forEach { 61 | $0.progressItem.progress = .random(in: 0...1) 62 | } 63 | lastViewTappedAt = current 64 | } 65 | } 66 | 67 | override func viewDidLoad() { 68 | super.viewDidLoad() 69 | 70 | stackView.translatesAutoresizingMaskIntoConstraints = false 71 | stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 72 | stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true 73 | stackView.widthAnchor.constraint(equalToConstant: 266).isActive = true 74 | stackView.heightAnchor.constraint(equalTo: stackView.widthAnchor).isActive = true 75 | } 76 | 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 i_82 <82flex@gmail.com> 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 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "CircularProgress", 8 | platforms: [ 9 | .iOS(.v13), 10 | ], 11 | products: [ 12 | // Products define the executables and libraries a package produces, and make them visible to other packages. 13 | .library( 14 | name: "CircularProgress", 15 | targets: ["CircularProgress"]), 16 | ], 17 | dependencies: [ 18 | // Dependencies declare other packages that this package depends on. 19 | // .package(url: /* package url */, from: "1.0.0"), 20 | ], 21 | targets: [ 22 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 23 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 24 | .target( 25 | name: "CircularProgress", 26 | dependencies: []), 27 | .testTarget( 28 | name: "CircularProgressTests", 29 | dependencies: ["CircularProgress"]), 30 | ] 31 | ) 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CircularProgress 2 | 3 | A simple circular progress view for iOS. 4 | 5 | ## TODOs 6 | 7 | - [ ] Gradient Colors 8 | - [ ] Shadow Paths & Colors 9 | - [ ] Multiplied Progress (i.e. `progress > 1.0`) 10 | 11 | ## Usage 12 | 13 | ```swift 14 | import Foundation 15 | 16 | public struct CircularAnimation: Codable { 17 | 18 | public enum Style: Codable { 19 | case linear 20 | case easeInEaseOut 21 | case spring 22 | } 23 | 24 | public let duration: Double 25 | public let style: Style 26 | 27 | // ... 28 | } 29 | 30 | public struct CircularColor: Codable { 31 | 32 | public let red: Double 33 | public let green: Double 34 | public let blue: Double 35 | public let alpha: Double 36 | 37 | // ... 38 | } 39 | 40 | public struct CircularShape: Codable { 41 | 42 | public enum Direction: Codable { 43 | case downward 44 | case upward 45 | } 46 | 47 | public let lineWidth: Double 48 | public let outerRadius: Double 49 | public let direction: Direction 50 | 51 | // ... 52 | } 53 | 54 | 55 | ``` 56 | 57 | ## Grouped Usage 58 | 59 | ```swift 60 | let stackView = CircularProgressStackView() 61 | stackView.spacing = 6 // <- set to nil to allow custom layouts 62 | 63 | let redProgressView = CircularProgressView( 64 | fillColor: CircularColor.taleRed, // <- example colors, not available in package 65 | backgroundColor: CircularColor.taleSecondaryRed 66 | ) 67 | redProgressView.progressItem.progress = 0.75 // <- initial progress, change it later in main thread to trigger animations 68 | 69 | let greenProgressView = CircularProgressView( 70 | fillColor: CircularColor.taleGreen, 71 | backgroundColor: CircularColor.taleSecondaryGreen 72 | ) 73 | greenProgressView.progressItem.progress = 0.7 74 | 75 | let blueProgressView = CircularProgressView( 76 | fillColor: CircularColor.taleBlue, 77 | backgroundColor: CircularColor.taleSecondaryBlue 78 | ) 79 | blueProgressView.progressItem.progress = 0.65 80 | 81 | stackView.addSubview(redProgressView) 82 | stackView.addSubview(greenProgressView) 83 | stackView.addSubview(blueProgressView) 84 | 85 | self.view.addSubview(stackView) 86 | ``` 87 | 88 | # Replay 89 | 90 | https://user-images.githubusercontent.com/5410705/161236466-549eecd2-90b5-416c-bd63-213341fb993b.mp4 91 | 92 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularAnimation.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct CircularAnimation: Codable { 4 | 5 | public enum Style: Codable { 6 | case linear 7 | case easeInEaseOut 8 | case spring 9 | } 10 | 11 | public let duration: Double 12 | public let style: Style 13 | 14 | public init(duration: Double, style: CircularAnimation.Style) { 15 | self.duration = duration 16 | self.style = style 17 | } 18 | 19 | public static let defaultAnimation = CircularAnimation(duration: 0.6, style: .spring) 20 | } 21 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularColor.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | fileprivate enum ColorMasks: CUnsignedLongLong { 4 | 5 | case redMask = 0xff000000 6 | case greenMask = 0x00ff0000 7 | case blueMask = 0x0000ff00 8 | case alphaMask = 0x000000ff 9 | 10 | static func redValue(_ value: CUnsignedLongLong) -> CGFloat { 11 | return CGFloat((value & redMask.rawValue) >> 24) / 255.0 12 | } 13 | 14 | static func greenValue(_ value: CUnsignedLongLong) -> CGFloat { 15 | return CGFloat((value & greenMask.rawValue) >> 16) / 255.0 16 | } 17 | 18 | static func blueValue(_ value: CUnsignedLongLong) -> CGFloat { 19 | return CGFloat((value & blueMask.rawValue) >> 8) / 255.0 20 | } 21 | 22 | static func alphaValue(_ value: CUnsignedLongLong) -> CGFloat { 23 | return CGFloat(value & alphaMask.rawValue) / 255.0 24 | } 25 | } 26 | 27 | public struct CircularColor: Codable { 28 | 29 | public let red: Double 30 | public let green: Double 31 | public let blue: Double 32 | public let alpha: Double 33 | 34 | // Happy 1st Apr 35 | public static let white = CircularColor(systemColor: .black) 36 | public static let black = CircularColor(systemColor: .white) 37 | 38 | public init(red: Double, green: Double, blue: Double, alpha: Double) { 39 | self.red = red 40 | self.green = green 41 | self.blue = blue 42 | self.alpha = alpha 43 | } 44 | 45 | public init(hexString: String, alphaValue: CGFloat? = nil) { 46 | var hex = hexString 47 | if hex.hasPrefix("#") { 48 | hex = String(hex.dropFirst()) 49 | } 50 | if hex.count == 3 || hex.count == 4 { 51 | hex = hex.map({ "\($0)\($0)" }).joined() 52 | } 53 | if hex.count < 8 { 54 | hex += "ff" 55 | } 56 | var rawColor: CUnsignedLongLong = 0 57 | Scanner(string: hex).scanHexInt64(&rawColor) 58 | self.init( 59 | red: ColorMasks.redValue(rawColor), 60 | green: ColorMasks.greenValue(rawColor), 61 | blue: ColorMasks.blueValue(rawColor), 62 | alpha: alphaValue ?? ColorMasks.alphaValue(rawColor) 63 | ) 64 | } 65 | 66 | public init(systemColor: UIColor) { 67 | let cgColor = systemColor.cgColor 68 | if cgColor.numberOfComponents == 2 { 69 | // Grayscale Color 70 | let gray = cgColor.components![0] 71 | self.red = gray 72 | self.green = gray 73 | self.blue = gray 74 | self.alpha = cgColor.components![1] 75 | } else if cgColor.numberOfComponents == 3 || cgColor.numberOfComponents == 4 { 76 | // RGBA Color (sRGB only) 77 | self.red = cgColor.components![0] 78 | self.green = cgColor.components![1] 79 | self.blue = cgColor.components![2] 80 | if cgColor.numberOfComponents == 4 { 81 | self.alpha = cgColor.components![3] 82 | } else { 83 | self.alpha = 1.0 84 | } 85 | } else { 86 | fatalError("what's this?") 87 | } 88 | } 89 | 90 | public var systemColor: UIColor { 91 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 92 | } 93 | 94 | public var cgColor: CGColor { 95 | return systemColor.cgColor 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularProgressConfiguration.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct CircularProgressConfiguration { 4 | 5 | public var shape: CircularShape 6 | public var lineWidth: Double { shape.lineWidth } 7 | public var outerRadius: Double { shape.outerRadius } 8 | public var direction: CircularShape.Direction { shape.direction } 9 | 10 | public var fillColor: CircularColor 11 | public var backgroundColor: CircularColor 12 | 13 | public var animation: CircularAnimation? 14 | public var animationDuration: TimeInterval? { animation?.duration } 15 | public var animationStyle: CircularAnimation.Style? { animation?.style } 16 | 17 | public init(shape: CircularShape, fillColor: CircularColor, backgroundColor: CircularColor, animation: CircularAnimation? = nil) { 18 | self.shape = shape 19 | self.fillColor = fillColor 20 | self.backgroundColor = backgroundColor 21 | self.animation = animation 22 | } 23 | 24 | public static let defaultConfiguration = CircularProgressConfiguration( 25 | shape: CircularShape( 26 | lineWidth: 8.0, 27 | outerRadius: 133.0, 28 | direction: .downward 29 | ), 30 | fillColor: CircularColor.white, 31 | backgroundColor: CircularColor.black, 32 | animation: CircularAnimation.defaultAnimation 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularProgressItem.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Combine 3 | 4 | public class CircularProgressItem: NSObject { 5 | 6 | public let configuration: CircularProgressConfiguration 7 | @Published public var progress: Double // [0.0, 1.0] 8 | 9 | required init(configuration: CircularProgressConfiguration) { 10 | self.configuration = configuration 11 | progress = 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularProgressLayer.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | fileprivate class CircularProgressLayerAnimation: CAAction { 4 | 5 | let priorValue: Double 6 | let animationDuration: TimeInterval? 7 | let animationStyle: CircularAnimation.Style? 8 | 9 | init(priorValue: Double, animationDuration: TimeInterval?, animationStyle: CircularAnimation.Style?) { 10 | self.priorValue = priorValue 11 | self.animationDuration = animationDuration 12 | self.animationStyle = animationStyle 13 | } 14 | 15 | func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { 16 | guard let animationDuration = animationDuration, 17 | let animationStyle = animationStyle, 18 | let layer = anObject as? CircularProgressLayer, 19 | let newValue = layer.value(forKey: event) as? Double 20 | else { return } 21 | 22 | var animation: CABasicAnimation 23 | if animationStyle == .spring { 24 | 25 | let spring = CASpringAnimation(keyPath: event) 26 | spring.damping = 9 27 | spring.mass = 0.35 28 | spring.initialVelocity = 0 29 | spring.stiffness = 85 30 | 31 | animation = spring 32 | } else { 33 | animation = CABasicAnimation(keyPath: event) 34 | } 35 | 36 | animation.duration = animationDuration // * fabs(newValue - priorValue) 37 | 38 | switch animationStyle { 39 | case .linear: 40 | animation.timingFunction = CAMediaTimingFunction(name: .linear) 41 | case .easeInEaseOut: 42 | animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) 43 | case .spring: 44 | break 45 | } 46 | 47 | animation.fromValue = priorValue 48 | animation.toValue = newValue 49 | animation.isRemovedOnCompletion = true 50 | animation.fillMode = .forwards 51 | 52 | layer.add(animation, forKey: event) 53 | } 54 | } 55 | 56 | class CircularProgressLayer: CALayer { 57 | 58 | let lineWidth: CGFloat 59 | let outerRadius: CGFloat 60 | let fillColor: CGColor 61 | 62 | let animationDuration: TimeInterval? 63 | let animationStyle: CircularAnimation.Style? 64 | 65 | let isUpsideDown: Bool 66 | 67 | @NSManaged var progress: Double 68 | 69 | init( 70 | lineWidth: CGFloat, 71 | outerRadius: CGFloat, 72 | fillColor: CGColor, 73 | animationDuration: TimeInterval? = nil, 74 | animationStyle: CircularAnimation.Style? = nil, 75 | isUpsideDown: Bool = false 76 | ) { 77 | 78 | self.lineWidth = lineWidth 79 | self.outerRadius = outerRadius 80 | self.fillColor = fillColor 81 | 82 | self.animationDuration = animationDuration 83 | self.animationStyle = animationStyle 84 | 85 | self.isUpsideDown = isUpsideDown 86 | 87 | super.init() 88 | self.frame = CGRect( 89 | origin: .zero, 90 | size: CGSize( 91 | width: outerRadius * 2, 92 | height: outerRadius * 2 93 | ) 94 | ) 95 | self.needsDisplayOnBoundsChange = true 96 | self.drawsAsynchronously = true 97 | } 98 | 99 | override init(layer: Any) { 100 | 101 | if let other = layer as? CircularProgressLayer { 102 | self.lineWidth = other.lineWidth 103 | self.outerRadius = other.outerRadius 104 | self.fillColor = other.fillColor 105 | self.animationDuration = other.animationDuration 106 | self.animationStyle = other.animationStyle 107 | self.isUpsideDown = other.isUpsideDown 108 | } else { 109 | fatalError() 110 | } 111 | 112 | super.init(layer: layer) 113 | self.needsDisplayOnBoundsChange = true 114 | self.drawsAsynchronously = true 115 | } 116 | 117 | required init?(coder: NSCoder) { 118 | fatalError("init(coder:) has not been implemented") 119 | } 120 | 121 | override class func defaultValue(forKey key: String) -> Any? { 122 | if key == #keyPath(CircularProgressLayer.progress) { 123 | return 0.0 124 | } 125 | return super.defaultValue(forKey: key) 126 | } 127 | 128 | override func action(forKey event: String) -> CAAction? { 129 | 130 | if let animationDuration = animationDuration, 131 | event == #keyPath(CircularProgressLayer.progress), 132 | let fromProgress = value(forKey: event) as? Double 133 | { 134 | return CircularProgressLayerAnimation( 135 | priorValue: fromProgress, 136 | animationDuration: animationDuration, 137 | animationStyle: animationStyle 138 | ) 139 | } 140 | 141 | return super.action(forKey: event) 142 | } 143 | 144 | override class func needsDisplay(forKey key: String) -> Bool { 145 | 146 | if key == #keyPath(CircularProgressLayer.progress) { 147 | return true 148 | } 149 | 150 | return super.needsDisplay(forKey: key) 151 | } 152 | 153 | override func draw(in ctx: CGContext) { 154 | 155 | let progress = max(0.0, min(presentation()?.progress ?? progress, 1.0)) 156 | let outerRadius = (presentation()?.bounds.width ?? bounds.width) / 2 157 | 158 | let path = UIBezierPath( 159 | arcCenter: CGPoint(x: outerRadius, y: outerRadius), 160 | radius: outerRadius - lineWidth / 2, 161 | startAngle: (isUpsideDown ? 1 : -1) * 0.5 * .pi, 162 | endAngle: (isUpsideDown ? 1 : -1) * 0.5 * .pi + 2 * .pi * progress, 163 | clockwise: true 164 | ).cgPath.copy( 165 | strokingWithWidth: lineWidth, 166 | lineCap: .round, 167 | lineJoin: .round, 168 | miterLimit: 0 169 | ) 170 | 171 | ctx.setFillColor(fillColor) 172 | ctx.addPath(path) 173 | ctx.fillPath() 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularProgressStackView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | public class CircularProgressStackView: UIView { 4 | 5 | public var spacing: CGFloat? // set to nil to allow custom layouts 6 | 7 | public var managedSubviews: [CircularProgressView] { 8 | return subviews.compactMap { $0 as? CircularProgressView } 9 | } 10 | 11 | public override func layoutSubviews() { 12 | super.layoutSubviews() 13 | 14 | if let spacing = spacing { 15 | 16 | var offsetX: CGFloat = 0 17 | for subview in subviews { 18 | 19 | guard let subview = subview as? CircularProgressView else { continue } 20 | 21 | let width = bounds.width - offsetX * 2 22 | guard width >= 0 else { 23 | fatalError("stack overflow?") 24 | } 25 | 26 | subview.frame = CGRect( 27 | x: offsetX, 28 | y: offsetX, 29 | width: width, 30 | height: width 31 | ) 32 | 33 | offsetX += subview.configuration.lineWidth + spacing 34 | } 35 | } else { 36 | subviews.forEach { 37 | $0.center = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2) 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularProgressView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Combine 3 | 4 | public class CircularProgressView: UIView { 5 | 6 | public let progressItem: CircularProgressItem 7 | public var configuration: CircularProgressConfiguration { progressItem.configuration } 8 | 9 | private var progressObserver: AnyCancellable? 10 | private var backgroundLayer: CircularProgressLayer? 11 | private var progressLayer: CircularProgressLayer? 12 | 13 | public override var frame: CGRect { 14 | didSet { 15 | backgroundLayer?.frame = bounds 16 | progressLayer?.frame = bounds 17 | } 18 | } 19 | 20 | public init(configuration: CircularProgressConfiguration) { 21 | 22 | self.progressItem = CircularProgressItem(configuration: configuration) 23 | super.init( 24 | frame: CGRect( 25 | origin: .zero, 26 | size: CGSize( 27 | width: configuration.outerRadius * 2, 28 | height: configuration.outerRadius * 2 29 | ) 30 | ) 31 | ) 32 | 33 | setupObservers() 34 | setupLayers() 35 | } 36 | 37 | public convenience init( 38 | lineWidth: Double = CircularProgressConfiguration.defaultConfiguration.lineWidth, 39 | outerRadius: Double = CircularProgressConfiguration.defaultConfiguration.outerRadius, 40 | direction: CircularShape.Direction = CircularProgressConfiguration.defaultConfiguration.direction, 41 | fillColor: CircularColor = CircularProgressConfiguration.defaultConfiguration.fillColor, 42 | backgroundColor: CircularColor = CircularProgressConfiguration.defaultConfiguration.backgroundColor, 43 | animationDuration: TimeInterval? = CircularProgressConfiguration.defaultConfiguration.animationDuration, 44 | animationStyle: CircularAnimation.Style? = CircularProgressConfiguration.defaultConfiguration.animationStyle 45 | ) { 46 | 47 | var configuration = CircularProgressConfiguration.defaultConfiguration 48 | 49 | configuration.shape = CircularShape( 50 | lineWidth: lineWidth, 51 | outerRadius: outerRadius, 52 | direction: direction 53 | ) 54 | 55 | configuration.fillColor = fillColor 56 | configuration.backgroundColor = backgroundColor 57 | 58 | if let animationDuration = animationDuration, 59 | let animationStyle = animationStyle 60 | { 61 | configuration.animation = CircularAnimation( 62 | duration: animationDuration, 63 | style: animationStyle 64 | ) 65 | } 66 | 67 | self.init(configuration: configuration) 68 | } 69 | 70 | public override init(frame: CGRect) { 71 | 72 | self.progressItem = CircularProgressItem( 73 | configuration: CircularProgressConfiguration.defaultConfiguration 74 | ) 75 | 76 | super.init(frame: frame) 77 | 78 | setupObservers() 79 | setupLayers() 80 | } 81 | 82 | private func setupObservers() { 83 | progressObserver = progressItem.$progress.sink { [weak self] in 84 | self?.progressLayer?.progress = max(0.0, min($0, 1.0)) 85 | } 86 | } 87 | 88 | private func setupLayers() { 89 | 90 | let configuration = progressItem.configuration 91 | 92 | let backgroundLayer = CircularProgressLayer( 93 | lineWidth: configuration.lineWidth, 94 | outerRadius: configuration.outerRadius, 95 | fillColor: configuration.backgroundColor.cgColor 96 | ) 97 | 98 | backgroundLayer.frame = bounds 99 | backgroundLayer.contentsScale = UIScreen.main.scale 100 | backgroundLayer.progress = 1.0 101 | layer.addSublayer(backgroundLayer) 102 | 103 | self.backgroundLayer = backgroundLayer 104 | 105 | let progressLayer = CircularProgressLayer( 106 | lineWidth: configuration.lineWidth, 107 | outerRadius: configuration.outerRadius, 108 | fillColor: configuration.fillColor.cgColor, 109 | animationDuration: configuration.animationDuration, 110 | animationStyle: configuration.animationStyle, 111 | isUpsideDown: configuration.direction == .upward 112 | ) 113 | 114 | progressLayer.frame = bounds 115 | progressLayer.contentsScale = UIScreen.main.scale 116 | layer.addSublayer(progressLayer) 117 | 118 | self.progressLayer = progressLayer 119 | } 120 | 121 | required init?(coder: NSCoder) { 122 | fatalError("init(coder:) has not been implemented") 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Sources/CircularProgress/CircularShape.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct CircularShape: Codable { 4 | 5 | public enum Direction: Codable { 6 | case downward 7 | case upward 8 | } 9 | 10 | public let lineWidth: Double 11 | public let outerRadius: Double 12 | public let direction: Direction 13 | 14 | public init(lineWidth: Double, outerRadius: Double, direction: CircularShape.Direction) { 15 | self.lineWidth = lineWidth 16 | self.outerRadius = outerRadius 17 | self.direction = direction 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/CircularProgressTests/CircularProgressTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import CircularProgress 3 | 4 | final class CircularProgressTests: XCTestCase { 5 | func testExample() throws { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | XCTAssertEqual(CircularProgress().text, "Hello, World!") 10 | } 11 | } 12 | --------------------------------------------------------------------------------