├── .gitignore ├── AngleGradientBorderTutorial.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── AngleGradientBorderTutorial.xcscmblueprint ├── AngleGradientBorderTutorial ├── AngleGradientBorderLayer.swift ├── AngleGradientBorderTutorial-Bridging-Header.h ├── AngleGradientBorderView.swift ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist └── ViewController.swift ├── AngleGradientBorderTutorialTests ├── AngleGradientBorderTutorialTests.swift └── Info.plist ├── AngleGradientLayer ├── AngleGradientLayer.h └── AngleGradientLayer.m └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | *.DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6548138619D8FD14000A4AA8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6548138519D8FD14000A4AA8 /* AppDelegate.swift */; }; 11 | 6548138819D8FD14000A4AA8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6548138719D8FD14000A4AA8 /* ViewController.swift */; }; 12 | 6548138B19D8FD14000A4AA8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6548138919D8FD14000A4AA8 /* Main.storyboard */; }; 13 | 6548138D19D8FD14000A4AA8 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6548138C19D8FD14000A4AA8 /* Images.xcassets */; }; 14 | 6548139019D8FD14000A4AA8 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6548138E19D8FD14000A4AA8 /* LaunchScreen.xib */; }; 15 | 6548139C19D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6548139B19D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.swift */; }; 16 | 654813AB19D9CA34000A4AA8 /* AngleGradientBorderLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 654813AA19D9CA34000A4AA8 /* AngleGradientBorderLayer.swift */; }; 17 | 654813AD19D9CAA0000A4AA8 /* AngleGradientBorderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 654813AC19D9CAA0000A4AA8 /* AngleGradientBorderView.swift */; }; 18 | 654813D019DF0780000A4AA8 /* AngleGradientLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 654813CF19DF0780000A4AA8 /* AngleGradientLayer.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 6548139619D8FD14000A4AA8 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 6548137819D8FD14000A4AA8 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 6548137F19D8FD14000A4AA8; 27 | remoteInfo = AngleGradientBorderTutorial; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 6548138019D8FD14000A4AA8 /* AngleGradientBorderTutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AngleGradientBorderTutorial.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 6548138419D8FD14000A4AA8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 6548138519D8FD14000A4AA8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 35 | 6548138719D8FD14000A4AA8 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 36 | 6548138A19D8FD14000A4AA8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37 | 6548138C19D8FD14000A4AA8 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 38 | 6548138F19D8FD14000A4AA8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 39 | 6548139519D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AngleGradientBorderTutorialTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 6548139A19D8FD14000A4AA8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 6548139B19D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AngleGradientBorderTutorialTests.swift; sourceTree = ""; }; 42 | 654813A919D9C943000A4AA8 /* AngleGradientBorderTutorial-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AngleGradientBorderTutorial-Bridging-Header.h"; sourceTree = ""; }; 43 | 654813AA19D9CA34000A4AA8 /* AngleGradientBorderLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AngleGradientBorderLayer.swift; sourceTree = ""; }; 44 | 654813AC19D9CAA0000A4AA8 /* AngleGradientBorderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AngleGradientBorderView.swift; sourceTree = ""; }; 45 | 654813CE19DF0780000A4AA8 /* AngleGradientLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AngleGradientLayer.h; path = AngleGradientLayer/AngleGradientLayer.h; sourceTree = ""; }; 46 | 654813CF19DF0780000A4AA8 /* AngleGradientLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AngleGradientLayer.m; path = AngleGradientLayer/AngleGradientLayer.m; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 6548137D19D8FD14000A4AA8 /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | 6548139219D8FD14000A4AA8 /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | /* End PBXFrameworksBuildPhase section */ 65 | 66 | /* Begin PBXGroup section */ 67 | 6548137719D8FD14000A4AA8 = { 68 | isa = PBXGroup; 69 | children = ( 70 | 654813D219DF07C4000A4AA8 /* AngleGradientLayer */, 71 | 6548138219D8FD14000A4AA8 /* AngleGradientBorderTutorial */, 72 | 6548139819D8FD14000A4AA8 /* AngleGradientBorderTutorialTests */, 73 | 6548138119D8FD14000A4AA8 /* Products */, 74 | ); 75 | sourceTree = ""; 76 | }; 77 | 6548138119D8FD14000A4AA8 /* Products */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 6548138019D8FD14000A4AA8 /* AngleGradientBorderTutorial.app */, 81 | 6548139519D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.xctest */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 6548138219D8FD14000A4AA8 /* AngleGradientBorderTutorial */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 654813D319DF083D000A4AA8 /* AngleGradientBorder */, 90 | 654813A919D9C943000A4AA8 /* AngleGradientBorderTutorial-Bridging-Header.h */, 91 | 6548138519D8FD14000A4AA8 /* AppDelegate.swift */, 92 | 6548138719D8FD14000A4AA8 /* ViewController.swift */, 93 | 6548138919D8FD14000A4AA8 /* Main.storyboard */, 94 | 6548138C19D8FD14000A4AA8 /* Images.xcassets */, 95 | 6548138E19D8FD14000A4AA8 /* LaunchScreen.xib */, 96 | 6548138319D8FD14000A4AA8 /* Supporting Files */, 97 | ); 98 | path = AngleGradientBorderTutorial; 99 | sourceTree = ""; 100 | }; 101 | 6548138319D8FD14000A4AA8 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 6548138419D8FD14000A4AA8 /* Info.plist */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | 6548139819D8FD14000A4AA8 /* AngleGradientBorderTutorialTests */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 6548139B19D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.swift */, 113 | 6548139919D8FD14000A4AA8 /* Supporting Files */, 114 | ); 115 | path = AngleGradientBorderTutorialTests; 116 | sourceTree = ""; 117 | }; 118 | 6548139919D8FD14000A4AA8 /* Supporting Files */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 6548139A19D8FD14000A4AA8 /* Info.plist */, 122 | ); 123 | name = "Supporting Files"; 124 | sourceTree = ""; 125 | }; 126 | 654813D219DF07C4000A4AA8 /* AngleGradientLayer */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 654813CE19DF0780000A4AA8 /* AngleGradientLayer.h */, 130 | 654813CF19DF0780000A4AA8 /* AngleGradientLayer.m */, 131 | ); 132 | name = AngleGradientLayer; 133 | sourceTree = ""; 134 | }; 135 | 654813D319DF083D000A4AA8 /* AngleGradientBorder */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 654813AA19D9CA34000A4AA8 /* AngleGradientBorderLayer.swift */, 139 | 654813AC19D9CAA0000A4AA8 /* AngleGradientBorderView.swift */, 140 | ); 141 | name = AngleGradientBorder; 142 | sourceTree = ""; 143 | }; 144 | /* End PBXGroup section */ 145 | 146 | /* Begin PBXNativeTarget section */ 147 | 6548137F19D8FD14000A4AA8 /* AngleGradientBorderTutorial */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 6548139F19D8FD14000A4AA8 /* Build configuration list for PBXNativeTarget "AngleGradientBorderTutorial" */; 150 | buildPhases = ( 151 | 6548137C19D8FD14000A4AA8 /* Sources */, 152 | 6548137D19D8FD14000A4AA8 /* Frameworks */, 153 | 6548137E19D8FD14000A4AA8 /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | ); 159 | name = AngleGradientBorderTutorial; 160 | productName = AngleGradientBorderTutorial; 161 | productReference = 6548138019D8FD14000A4AA8 /* AngleGradientBorderTutorial.app */; 162 | productType = "com.apple.product-type.application"; 163 | }; 164 | 6548139419D8FD14000A4AA8 /* AngleGradientBorderTutorialTests */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = 654813A219D8FD14000A4AA8 /* Build configuration list for PBXNativeTarget "AngleGradientBorderTutorialTests" */; 167 | buildPhases = ( 168 | 6548139119D8FD14000A4AA8 /* Sources */, 169 | 6548139219D8FD14000A4AA8 /* Frameworks */, 170 | 6548139319D8FD14000A4AA8 /* Resources */, 171 | ); 172 | buildRules = ( 173 | ); 174 | dependencies = ( 175 | 6548139719D8FD14000A4AA8 /* PBXTargetDependency */, 176 | ); 177 | name = AngleGradientBorderTutorialTests; 178 | productName = AngleGradientBorderTutorialTests; 179 | productReference = 6548139519D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.xctest */; 180 | productType = "com.apple.product-type.bundle.unit-test"; 181 | }; 182 | /* End PBXNativeTarget section */ 183 | 184 | /* Begin PBXProject section */ 185 | 6548137819D8FD14000A4AA8 /* Project object */ = { 186 | isa = PBXProject; 187 | attributes = { 188 | LastSwiftMigration = 0730; 189 | LastSwiftUpdateCheck = 0730; 190 | LastUpgradeCheck = 0600; 191 | ORGANIZATIONNAME = "Ian Hirschfeld"; 192 | TargetAttributes = { 193 | 6548137F19D8FD14000A4AA8 = { 194 | CreatedOnToolsVersion = 6.0.1; 195 | LastSwiftMigration = 0800; 196 | }; 197 | 6548139419D8FD14000A4AA8 = { 198 | CreatedOnToolsVersion = 6.0.1; 199 | LastSwiftMigration = 0800; 200 | TestTargetID = 6548137F19D8FD14000A4AA8; 201 | }; 202 | }; 203 | }; 204 | buildConfigurationList = 6548137B19D8FD14000A4AA8 /* Build configuration list for PBXProject "AngleGradientBorderTutorial" */; 205 | compatibilityVersion = "Xcode 3.2"; 206 | developmentRegion = English; 207 | hasScannedForEncodings = 0; 208 | knownRegions = ( 209 | en, 210 | Base, 211 | ); 212 | mainGroup = 6548137719D8FD14000A4AA8; 213 | productRefGroup = 6548138119D8FD14000A4AA8 /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | 6548137F19D8FD14000A4AA8 /* AngleGradientBorderTutorial */, 218 | 6548139419D8FD14000A4AA8 /* AngleGradientBorderTutorialTests */, 219 | ); 220 | }; 221 | /* End PBXProject section */ 222 | 223 | /* Begin PBXResourcesBuildPhase section */ 224 | 6548137E19D8FD14000A4AA8 /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | 6548138B19D8FD14000A4AA8 /* Main.storyboard in Resources */, 229 | 6548139019D8FD14000A4AA8 /* LaunchScreen.xib in Resources */, 230 | 6548138D19D8FD14000A4AA8 /* Images.xcassets in Resources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | 6548139319D8FD14000A4AA8 /* Resources */ = { 235 | isa = PBXResourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXSourcesBuildPhase section */ 244 | 6548137C19D8FD14000A4AA8 /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 6548138819D8FD14000A4AA8 /* ViewController.swift in Sources */, 249 | 654813AB19D9CA34000A4AA8 /* AngleGradientBorderLayer.swift in Sources */, 250 | 654813AD19D9CAA0000A4AA8 /* AngleGradientBorderView.swift in Sources */, 251 | 6548138619D8FD14000A4AA8 /* AppDelegate.swift in Sources */, 252 | 654813D019DF0780000A4AA8 /* AngleGradientLayer.m in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | 6548139119D8FD14000A4AA8 /* Sources */ = { 257 | isa = PBXSourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | 6548139C19D8FD14000A4AA8 /* AngleGradientBorderTutorialTests.swift in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXSourcesBuildPhase section */ 265 | 266 | /* Begin PBXTargetDependency section */ 267 | 6548139719D8FD14000A4AA8 /* PBXTargetDependency */ = { 268 | isa = PBXTargetDependency; 269 | target = 6548137F19D8FD14000A4AA8 /* AngleGradientBorderTutorial */; 270 | targetProxy = 6548139619D8FD14000A4AA8 /* PBXContainerItemProxy */; 271 | }; 272 | /* End PBXTargetDependency section */ 273 | 274 | /* Begin PBXVariantGroup section */ 275 | 6548138919D8FD14000A4AA8 /* Main.storyboard */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | 6548138A19D8FD14000A4AA8 /* Base */, 279 | ); 280 | name = Main.storyboard; 281 | sourceTree = ""; 282 | }; 283 | 6548138E19D8FD14000A4AA8 /* LaunchScreen.xib */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 6548138F19D8FD14000A4AA8 /* Base */, 287 | ); 288 | name = LaunchScreen.xib; 289 | sourceTree = ""; 290 | }; 291 | /* End PBXVariantGroup section */ 292 | 293 | /* Begin XCBuildConfiguration section */ 294 | 6548139D19D8FD14000A4AA8 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ALWAYS_SEARCH_USER_PATHS = NO; 298 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 299 | CLANG_CXX_LIBRARY = "libc++"; 300 | CLANG_ENABLE_MODULES = YES; 301 | CLANG_ENABLE_OBJC_ARC = YES; 302 | CLANG_WARN_BOOL_CONVERSION = YES; 303 | CLANG_WARN_CONSTANT_CONVERSION = YES; 304 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 305 | CLANG_WARN_EMPTY_BODY = YES; 306 | CLANG_WARN_ENUM_CONVERSION = YES; 307 | CLANG_WARN_INT_CONVERSION = YES; 308 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 309 | CLANG_WARN_UNREACHABLE_CODE = YES; 310 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 311 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 312 | COPY_PHASE_STRIP = NO; 313 | ENABLE_STRICT_OBJC_MSGSEND = YES; 314 | GCC_C_LANGUAGE_STANDARD = gnu99; 315 | GCC_DYNAMIC_NO_PIC = NO; 316 | GCC_OPTIMIZATION_LEVEL = 0; 317 | GCC_PREPROCESSOR_DEFINITIONS = ( 318 | "DEBUG=1", 319 | "$(inherited)", 320 | ); 321 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 322 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 323 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 324 | GCC_WARN_UNDECLARED_SELECTOR = YES; 325 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 326 | GCC_WARN_UNUSED_FUNCTION = YES; 327 | GCC_WARN_UNUSED_VARIABLE = YES; 328 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 329 | MTL_ENABLE_DEBUG_INFO = YES; 330 | ONLY_ACTIVE_ARCH = YES; 331 | SDKROOT = iphoneos; 332 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 333 | }; 334 | name = Debug; 335 | }; 336 | 6548139E19D8FD14000A4AA8 /* Release */ = { 337 | isa = XCBuildConfiguration; 338 | buildSettings = { 339 | ALWAYS_SEARCH_USER_PATHS = NO; 340 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 341 | CLANG_CXX_LIBRARY = "libc++"; 342 | CLANG_ENABLE_MODULES = YES; 343 | CLANG_ENABLE_OBJC_ARC = YES; 344 | CLANG_WARN_BOOL_CONVERSION = YES; 345 | CLANG_WARN_CONSTANT_CONVERSION = YES; 346 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 347 | CLANG_WARN_EMPTY_BODY = YES; 348 | CLANG_WARN_ENUM_CONVERSION = YES; 349 | CLANG_WARN_INT_CONVERSION = YES; 350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 351 | CLANG_WARN_UNREACHABLE_CODE = YES; 352 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 353 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 354 | COPY_PHASE_STRIP = YES; 355 | ENABLE_NS_ASSERTIONS = NO; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 365 | MTL_ENABLE_DEBUG_INFO = NO; 366 | SDKROOT = iphoneos; 367 | VALIDATE_PRODUCT = YES; 368 | }; 369 | name = Release; 370 | }; 371 | 654813A019D8FD14000A4AA8 /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 375 | INFOPLIST_FILE = AngleGradientBorderTutorial/Info.plist; 376 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 377 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 378 | PRODUCT_BUNDLE_IDENTIFIER = com.ianhirschfeld.tutorials.AngleGradientBorderTutorial; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | SWIFT_OBJC_BRIDGING_HEADER = "AngleGradientBorderTutorial/AngleGradientBorderTutorial-Bridging-Header.h"; 381 | SWIFT_VERSION = 3.0; 382 | }; 383 | name = Debug; 384 | }; 385 | 654813A119D8FD14000A4AA8 /* Release */ = { 386 | isa = XCBuildConfiguration; 387 | buildSettings = { 388 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 389 | INFOPLIST_FILE = AngleGradientBorderTutorial/Info.plist; 390 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 391 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 392 | PRODUCT_BUNDLE_IDENTIFIER = com.ianhirschfeld.tutorials.AngleGradientBorderTutorial; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | SWIFT_OBJC_BRIDGING_HEADER = "AngleGradientBorderTutorial/AngleGradientBorderTutorial-Bridging-Header.h"; 395 | SWIFT_VERSION = 3.0; 396 | }; 397 | name = Release; 398 | }; 399 | 654813A319D8FD14000A4AA8 /* Debug */ = { 400 | isa = XCBuildConfiguration; 401 | buildSettings = { 402 | BUNDLE_LOADER = "$(TEST_HOST)"; 403 | FRAMEWORK_SEARCH_PATHS = ( 404 | "$(SDKROOT)/Developer/Library/Frameworks", 405 | "$(inherited)", 406 | ); 407 | GCC_PREPROCESSOR_DEFINITIONS = ( 408 | "DEBUG=1", 409 | "$(inherited)", 410 | ); 411 | INFOPLIST_FILE = AngleGradientBorderTutorialTests/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | SWIFT_VERSION = 3.0; 415 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AngleGradientBorderTutorial.app/AngleGradientBorderTutorial"; 416 | }; 417 | name = Debug; 418 | }; 419 | 654813A419D8FD14000A4AA8 /* Release */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | BUNDLE_LOADER = "$(TEST_HOST)"; 423 | FRAMEWORK_SEARCH_PATHS = ( 424 | "$(SDKROOT)/Developer/Library/Frameworks", 425 | "$(inherited)", 426 | ); 427 | INFOPLIST_FILE = AngleGradientBorderTutorialTests/Info.plist; 428 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 429 | PRODUCT_NAME = "$(TARGET_NAME)"; 430 | SWIFT_VERSION = 3.0; 431 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AngleGradientBorderTutorial.app/AngleGradientBorderTutorial"; 432 | }; 433 | name = Release; 434 | }; 435 | /* End XCBuildConfiguration section */ 436 | 437 | /* Begin XCConfigurationList section */ 438 | 6548137B19D8FD14000A4AA8 /* Build configuration list for PBXProject "AngleGradientBorderTutorial" */ = { 439 | isa = XCConfigurationList; 440 | buildConfigurations = ( 441 | 6548139D19D8FD14000A4AA8 /* Debug */, 442 | 6548139E19D8FD14000A4AA8 /* Release */, 443 | ); 444 | defaultConfigurationIsVisible = 0; 445 | defaultConfigurationName = Release; 446 | }; 447 | 6548139F19D8FD14000A4AA8 /* Build configuration list for PBXNativeTarget "AngleGradientBorderTutorial" */ = { 448 | isa = XCConfigurationList; 449 | buildConfigurations = ( 450 | 654813A019D8FD14000A4AA8 /* Debug */, 451 | 654813A119D8FD14000A4AA8 /* Release */, 452 | ); 453 | defaultConfigurationIsVisible = 0; 454 | defaultConfigurationName = Release; 455 | }; 456 | 654813A219D8FD14000A4AA8 /* Build configuration list for PBXNativeTarget "AngleGradientBorderTutorialTests" */ = { 457 | isa = XCConfigurationList; 458 | buildConfigurations = ( 459 | 654813A319D8FD14000A4AA8 /* Debug */, 460 | 654813A419D8FD14000A4AA8 /* Release */, 461 | ); 462 | defaultConfigurationIsVisible = 0; 463 | defaultConfigurationName = Release; 464 | }; 465 | /* End XCConfigurationList section */ 466 | }; 467 | rootObject = 6548137819D8FD14000A4AA8 /* Project object */; 468 | } 469 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial.xcodeproj/project.xcworkspace/xcshareddata/AngleGradientBorderTutorial.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "FFB13BC18BD8D1C63567453019BF4D81D77BEBCF", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "5E221C555955B9572C5ECAC1ADDCDFBAF5BA6293" : 0, 8 | "FFB13BC18BD8D1C63567453019BF4D81D77BEBCF" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B9977B4E-33FC-4F3C-9092-7B2DCF8A5494", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "5E221C555955B9572C5ECAC1ADDCDFBAF5BA6293" : "AngleGradientLayer", 13 | "FFB13BC18BD8D1C63567453019BF4D81D77BEBCF" : "AngleGradientBorderTutorial\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "AngleGradientBorderTutorial", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "AngleGradientBorderTutorial.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:ianhirschfeld\/AngleGradientLayer.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "5E221C555955B9572C5ECAC1ADDCDFBAF5BA6293" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:ianhirschfeld\/AngleGradientBorderTutorial.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "FFB13BC18BD8D1C63567453019BF4D81D77BEBCF" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/AngleGradientBorderLayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleGradientBorderLayer.swift 3 | // AngleGradientBorderTutorial 4 | // 5 | // Created by Ian Hirschfeld on 9/29/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AngleGradientBorderLayer: AngleGradientLayer { 12 | 13 | // Properties 14 | var gradientBorderWidth: CGFloat = 1 15 | 16 | // Override to add a border shape to AngleGradientLayer. 17 | override func draw(in ctx: CGContext) { 18 | // Draw a shape that fills the view minus the width of your final border. 19 | // This can be any shape you want to make a border out of. 20 | // This example draws a circle. 21 | let shapePath = UIBezierPath(roundedRect: bounds.insetBy(dx: gradientBorderWidth, dy: gradientBorderWidth), cornerRadius: bounds.height / 2) 22 | 23 | // Copy the path of the shape and turn it into a stroke. 24 | let shapeCopyPath = CGPath(__byStroking: shapePath.cgPath, transform: nil, lineWidth: gradientBorderWidth, lineCap: CGLineCap.butt, lineJoin: CGLineJoin.bevel, miterLimit: 0) 25 | 26 | ctx.saveGState() 27 | 28 | // Add the stroked path to the context and clip to it. 29 | ctx.addPath(shapeCopyPath!) 30 | ctx.clip() 31 | 32 | // Call our super class's (AngleGradientLayer) #drawInContext 33 | // which will do the work to create the gradient. 34 | super.draw(in: ctx) 35 | 36 | ctx.restoreGState() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/AngleGradientBorderTutorial-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // AngleGradientBorderTutorial-Bridging-Header.h 3 | // AngleGradientBorderTutorial 4 | // 5 | // Created by Ian Hirschfeld on 9/29/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | #import "AngleGradientLayer.h" 10 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/AngleGradientBorderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleGradientBorderView.swift 3 | // AngleGradientBorderTutorial 4 | // 5 | // Created by Ian Hirschfeld on 9/29/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AngleGradientBorderView: UIView { 12 | 13 | // Constants 14 | let DefaultGradientBorderColors: [AnyObject] = [ 15 | UIColor.red.cgColor, 16 | UIColor.green.cgColor, 17 | UIColor.blue.cgColor, 18 | UIColor.red.cgColor, // Repeat the first color to make a smooth transition 19 | ] 20 | let DefaultGradientBorderWidth: CGFloat = 4 21 | 22 | // Set the UIView's layer class to be our AngleGradientBorderLayer 23 | override class var layerClass : AnyClass { 24 | return AngleGradientBorderLayer.self 25 | } 26 | 27 | // Initializer 28 | required init?(coder aDecoder: NSCoder) { 29 | super.init(coder: aDecoder) 30 | setupGradientLayer() 31 | } 32 | 33 | // Custom initializer 34 | init(frame: CGRect, borderColors gradientBorderColors: [AnyObject]? = nil, borderWidth gradientBorderWidth: CGFloat? = nil) { 35 | super.init(frame: frame) 36 | setupGradientLayer(borderColors: gradientBorderColors, borderWidth: gradientBorderWidth) 37 | } 38 | 39 | // Setup the attributes of this view's layer 40 | func setupGradientLayer(borderColors gradientBorderColors: [AnyObject]? = nil, borderWidth gradientBorderWidth: CGFloat? = nil) { 41 | // Grab this UIView's layer and cast it as AngleGradientBorderLayer 42 | let l: AngleGradientBorderLayer = self.layer as! AngleGradientBorderLayer 43 | 44 | // NOTE: Since our gradient layer is built as an image, 45 | // we need to scale it to match the display of the device. 46 | l.contentsScale = UIScreen.main.scale 47 | 48 | // Set the gradient colors 49 | if gradientBorderColors != nil { 50 | l.colors = gradientBorderColors! 51 | } else { 52 | l.colors = DefaultGradientBorderColors 53 | } 54 | 55 | // Set the border width of the gradient 56 | if gradientBorderWidth != nil { 57 | l.gradientBorderWidth = gradientBorderWidth! 58 | } else { 59 | l.gradientBorderWidth = DefaultGradientBorderWidth 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AngleGradientBorderTutorial 4 | // 5 | // Created by Ian Hirschfeld on 9/28/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorial/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AngleGradientBorderTutorial 4 | // 5 | // Created by Ian Hirschfeld on 9/28/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // UI 14 | @IBOutlet var angleGradientBorderView1: AngleGradientBorderView! 15 | @IBOutlet var angleGradientBorderView2: AngleGradientBorderView! 16 | @IBOutlet var angleGradientBorderView3: AngleGradientBorderView! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | let angleGradientBorderView1Colors: [AnyObject] = [ 22 | UIColor.purple.cgColor, 23 | UIColor.yellow.cgColor, 24 | UIColor.orange.cgColor, 25 | UIColor.purple.cgColor, 26 | ] 27 | // Change the colors of angleGradientBorderView1 and its border width 28 | angleGradientBorderView1.setupGradientLayer(borderColors: angleGradientBorderView1Colors, borderWidth: 5) 29 | 30 | let angleGradientBorderView3Colors: [AnyObject] = [ 31 | UIColor.red.cgColor, 32 | UIColor.orange.cgColor, 33 | UIColor.yellow.cgColor, 34 | UIColor.green.cgColor, 35 | UIColor.blue.cgColor, 36 | UIColor.purple.cgColor, 37 | UIColor.magenta.cgColor, 38 | UIColor.red.cgColor, 39 | ] 40 | // Change the colors of angleGradientBorderView1 and its border width 41 | angleGradientBorderView3.setupGradientLayer(borderColors: angleGradientBorderView3Colors, borderWidth: 10) 42 | 43 | // Add some animation 44 | scaleDownView() 45 | rotateView() 46 | } 47 | 48 | func scaleDownView() { 49 | let animation = CABasicAnimation(keyPath: "transform.scale") 50 | animation.fromValue = 1 51 | animation.toValue = 0.5 52 | animation.duration = 2 53 | animation.isRemovedOnCompletion = true 54 | animation.delegate = self 55 | animation.setValue("shrink", forKey: "animationId") 56 | angleGradientBorderView1.layer.add(animation, forKey: "shrink") 57 | angleGradientBorderView1.layer.transform = CATransform3DScale(CATransform3DIdentity, 0.5, 0.5, 1) 58 | } 59 | 60 | func scaleUpView() { 61 | let animation = CABasicAnimation(keyPath: "transform.scale") 62 | animation.fromValue = 0.5 63 | animation.toValue = 1 64 | animation.duration = 2 65 | animation.isRemovedOnCompletion = true 66 | animation.delegate = self 67 | animation.setValue("grow", forKey: "animationId") 68 | angleGradientBorderView1.layer.add(animation, forKey: "grow") 69 | angleGradientBorderView1.layer.transform = CATransform3DIdentity 70 | } 71 | 72 | func rotateView() { 73 | let animation = CABasicAnimation(keyPath: "transform.rotation") 74 | animation.fromValue = 0 75 | animation.toValue = 2 * M_PI 76 | animation.duration = 3 77 | animation.isRemovedOnCompletion = true 78 | animation.delegate = self 79 | animation.setValue("spin", forKey: "animationId") 80 | angleGradientBorderView3.layer.add(animation, forKey: "spin") 81 | } 82 | 83 | } 84 | 85 | extension ViewController: CAAnimationDelegate { 86 | 87 | func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { 88 | if flag { 89 | if let id: String = anim.value(forKey: "animationId") as? String { 90 | switch id { 91 | case "shrink": 92 | scaleUpView() 93 | 94 | case "grow": 95 | scaleDownView() 96 | 97 | case "spin": 98 | rotateView() 99 | 100 | default: 101 | break 102 | } 103 | } 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorialTests/AngleGradientBorderTutorialTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleGradientBorderTutorialTests.swift 3 | // AngleGradientBorderTutorialTests 4 | // 5 | // Created by Ian Hirschfeld on 9/28/14. 6 | // Copyright (c) 2014 Ian Hirschfeld. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class AngleGradientBorderTutorialTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /AngleGradientBorderTutorialTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.tutorials.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /AngleGradientLayer/AngleGradientLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // The MIT License (MIT) 3 | // 4 | // Copyright (C) 2012 Pavel Ivashkov 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software 7 | // and associated documentation files (the "Software"), to deal in the Software without restriction, 8 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, 9 | // sublicense, and/or sell 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 copies or 13 | // substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 17 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 18 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | // DEALINGS IN THE SOFTWARE. 21 | // 22 | // 23 | // AngleGradientLayer.h 24 | // paiv 25 | // 26 | // Created by Pavel Ivashkov on 2012-02-12. 27 | // 28 | 29 | #import 30 | 31 | 32 | @interface AngleGradientLayer : CALayer 33 | 34 | /* The array of CGColorRef objects defining the color of each gradient 35 | * stop. Defaults to nil. */ 36 | 37 | @property(copy) NSArray *colors; 38 | 39 | /* An optional array of NSNumber objects defining the location of each 40 | * gradient stop as a value in the range [0,1]. The values must be 41 | * monotonically increasing. If a nil array is given, the stops are 42 | * assumed to spread uniformly across the [0,1] range. When rendered, 43 | * the colors are mapped to the output colorspace before being 44 | * interpolated. Defaults to nil. */ 45 | 46 | @property(copy) NSArray *locations; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /AngleGradientLayer/AngleGradientLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // The MIT License (MIT) 3 | // 4 | // Copyright (C) 2012 Pavel Ivashkov 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 7 | // software and associated documentation files (the "Software"), to deal in the Software 8 | // without restriction, including without limitation the rights to use, copy, modify, merge, 9 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 10 | // to whom the Software is furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all copies or 13 | // substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 17 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 18 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | // DEALINGS IN THE SOFTWARE. 21 | // 22 | // 23 | // AngleGradientLayer.m 24 | // paiv 25 | // 26 | // Created by Pavel Ivashkov on 2012-02-12. 27 | // 28 | 29 | #import "AngleGradientLayer.h" 30 | 31 | #if __has_feature(objc_arc) 32 | #define BRIDGE_CAST(T) (__bridge T) 33 | #else 34 | #define BRIDGE_CAST(T) (T) 35 | #endif 36 | 37 | #define byte unsigned char 38 | #define F2CC(x) ((byte)(255 * x)) 39 | #define RGBAF(r,g,b,a) (F2CC(r) << 24 | F2CC(g) << 16 | F2CC(b) << 8 | F2CC(a)) 40 | #define RGBA(r,g,b,a) ((byte)r << 24 | (byte)g << 16 | (byte)b << 8 | (byte)a) 41 | #define RGBA_R(c) ((uint)c >> 24 & 255) 42 | #define RGBA_G(c) ((uint)c >> 16 & 255) 43 | #define RGBA_B(c) ((uint)c >> 8 & 255) 44 | #define RGBA_A(c) ((uint)c >> 0 & 255) 45 | 46 | @interface AngleGradientLayer() 47 | 48 | - (CGImageRef)newImageGradientInRect:(CGRect)rect; 49 | 50 | @end 51 | 52 | 53 | static void angleGradient(byte* data, int w, int h, int* colors, int colorCount, float* locations, int locationCount); 54 | 55 | 56 | @implementation AngleGradientLayer 57 | 58 | - (id)init 59 | { 60 | if (!(self = [super init])) 61 | return nil; 62 | 63 | self.needsDisplayOnBoundsChange = YES; 64 | 65 | return self; 66 | } 67 | 68 | #if !__has_feature(objc_arc) 69 | - (void)dealloc 70 | { 71 | [_colors release]; 72 | [_locations release]; 73 | [super dealloc]; 74 | } 75 | #endif 76 | 77 | - (void)drawInContext:(CGContextRef)ctx 78 | { 79 | CGRect rect = CGContextGetClipBoundingBox(ctx); 80 | CGImageRef img = [self newImageGradientInRect:rect]; 81 | CGContextDrawImage(ctx, rect, img); 82 | CGImageRelease(img); 83 | } 84 | 85 | - (CGImageRef)newImageGradientInRect:(CGRect)rect 86 | { 87 | int w = CGRectGetWidth(rect); 88 | int h = CGRectGetHeight(rect); 89 | int bitsPerComponent = 8; 90 | int bpp = 4 * bitsPerComponent / 8; 91 | int byteCount = w * h * bpp; 92 | 93 | int colorCount = (int)self.colors.count; 94 | int locationCount = 0; 95 | int* colors = NULL; 96 | float* locations = NULL; 97 | 98 | if (colorCount > 0) { 99 | colors = calloc(colorCount, bpp); 100 | int *p = colors; 101 | for (id cg in self.colors) { 102 | CGColorRef c = BRIDGE_CAST(CGColorRef)cg; 103 | float r, g, b, a; 104 | 105 | size_t n = CGColorGetNumberOfComponents(c); 106 | const CGFloat *comps = CGColorGetComponents(c); 107 | if (comps == NULL) { 108 | *p++ = 0; 109 | continue; 110 | } 111 | r = comps[0]; 112 | if (n >= 4) { 113 | g = comps[1]; 114 | b = comps[2]; 115 | a = comps[3]; 116 | } 117 | else { 118 | g = b = r; 119 | a = comps[1]; 120 | } 121 | *p++ = RGBAF(r, g, b, a); 122 | } 123 | } 124 | if (self.locations.count > 0 && self.locations.count == colorCount) { 125 | locationCount = (int)self.locations.count; 126 | locations = calloc(locationCount, sizeof(locations[0])); 127 | float *p = locations; 128 | for (NSNumber *n in self.locations) { 129 | *p++ = [n floatValue]; 130 | } 131 | } 132 | 133 | byte* data = malloc(byteCount); 134 | angleGradient(data, w, h, colors, colorCount, locations, locationCount); 135 | 136 | if (colors) free(colors); 137 | if (locations) free(locations); 138 | 139 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 140 | CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Little; 141 | CGContextRef ctx = CGBitmapContextCreate(data, w, h, bitsPerComponent, w * bpp, colorSpace, bitmapInfo); 142 | CGColorSpaceRelease(colorSpace); 143 | CGImageRef img = CGBitmapContextCreateImage(ctx); 144 | CGContextRelease(ctx); 145 | free(data); 146 | return img; 147 | } 148 | 149 | @end 150 | 151 | static inline byte blerp(byte a, byte b, float w) 152 | { 153 | return a + w * (b - a); 154 | } 155 | static inline int lerp(int a, int b, float w) 156 | { 157 | return RGBA(blerp(RGBA_R(a), RGBA_R(b), w), 158 | blerp(RGBA_G(a), RGBA_G(b), w), 159 | blerp(RGBA_B(a), RGBA_B(b), w), 160 | blerp(RGBA_A(a), RGBA_A(b), w)); 161 | } 162 | static inline int multiplyByAlpha(int c) 163 | { 164 | float a = RGBA_A(c) / 255.0; 165 | return RGBA((byte)(RGBA_R(c) * a), 166 | (byte)(RGBA_G(c) * a), 167 | (byte)(RGBA_B(c) * a), 168 | RGBA_A(c)); 169 | } 170 | 171 | void angleGradient(byte* data, int w, int h, int* colors, int colorCount, float* locations, int locationCount) 172 | { 173 | if (colorCount < 1) return; 174 | if (locationCount > 0 && locationCount != colorCount) return; 175 | 176 | int* p = (int*)data; 177 | float centerX = (float)w / 2; 178 | float centerY = (float)h / 2; 179 | 180 | for (int y = 0; y < h; y++) 181 | for (int x = 0; x < w; x++) { 182 | float dirX = x - centerX; 183 | float dirY = y - centerY; 184 | float angle = atan2f(dirY, dirX); 185 | if (dirY < 0) angle += 2 * M_PI; 186 | angle /= 2 * M_PI; 187 | 188 | int index = 0, nextIndex = 0; 189 | float t = 0; 190 | 191 | if (locationCount > 0) { 192 | for (index = locationCount - 1; index >= 0; index--) { 193 | if (angle >= locations[index]) { 194 | break; 195 | } 196 | } 197 | if (index >= locationCount) index = locationCount - 1; 198 | nextIndex = index + 1; 199 | if (nextIndex >= locationCount) nextIndex = locationCount - 1; 200 | float ld = locations[nextIndex] - locations[index]; 201 | t = ld <= 0 ? 0 : (angle - locations[index]) / ld; 202 | } 203 | else { 204 | t = angle * (colorCount - 1); 205 | index = t; 206 | t -= index; 207 | nextIndex = index + 1; 208 | if (nextIndex >= colorCount) nextIndex = colorCount - 1; 209 | } 210 | 211 | int lc = colors[index]; 212 | int rc = colors[nextIndex]; 213 | int color = lerp(lc, rc, t); 214 | color = multiplyByAlpha(color); 215 | *p++ = color; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AngleGradientBorderTutorial 2 | =========================== 3 | 4 | Sample code for creating a border filled with an angle gradient in iOS Swift. 5 | 6 | [Read the tutorial that goes along with this code.](https://medium.com/@ianhirschfeld/how-to-create-an-angle-gradient-border-in-swift-f4856dde4c90) 7 | --------------------------------------------------------------------------------