├── ButtonColorGradientAnimation.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── ls.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── ls.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── ButtonColorGradientAnimation ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── ButtonColorGradientAnimationTests ├── ButtonColorGradientAnimationTests.swift └── Info.plist ├── ButtonColorGradientAnimationUITests ├── ButtonColorGradientAnimationUITests.swift └── Info.plist ├── README.md └── pre.gif /ButtonColorGradientAnimation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 49AB0D9E2084C8C700F4FD0D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AB0D9D2084C8C700F4FD0D /* AppDelegate.swift */; }; 11 | 49AB0DA02084C8C700F4FD0D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AB0D9F2084C8C700F4FD0D /* ViewController.swift */; }; 12 | 49AB0DA32084C8C700F4FD0D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 49AB0DA12084C8C700F4FD0D /* Main.storyboard */; }; 13 | 49AB0DA52084C8C900F4FD0D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 49AB0DA42084C8C900F4FD0D /* Assets.xcassets */; }; 14 | 49AB0DA82084C8C900F4FD0D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 49AB0DA62084C8C900F4FD0D /* LaunchScreen.storyboard */; }; 15 | 49AB0DB32084C8C900F4FD0D /* ButtonColorGradientAnimationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AB0DB22084C8C900F4FD0D /* ButtonColorGradientAnimationTests.swift */; }; 16 | 49AB0DBE2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AB0DBD2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 49AB0DAF2084C8C900F4FD0D /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 49AB0D922084C8C700F4FD0D /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 49AB0D992084C8C700F4FD0D; 25 | remoteInfo = ButtonColorGradientAnimation; 26 | }; 27 | 49AB0DBA2084C8CA00F4FD0D /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = 49AB0D922084C8C700F4FD0D /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = 49AB0D992084C8C700F4FD0D; 32 | remoteInfo = ButtonColorGradientAnimation; 33 | }; 34 | /* End PBXContainerItemProxy section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | 49AB0D9A2084C8C700F4FD0D /* ButtonColorGradientAnimation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ButtonColorGradientAnimation.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 49AB0D9D2084C8C700F4FD0D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 49AB0D9F2084C8C700F4FD0D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 40 | 49AB0DA22084C8C700F4FD0D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 49AB0DA42084C8C900F4FD0D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 42 | 49AB0DA72084C8C900F4FD0D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 43 | 49AB0DA92084C8C900F4FD0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 49AB0DAE2084C8C900F4FD0D /* ButtonColorGradientAnimationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ButtonColorGradientAnimationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 49AB0DB22084C8C900F4FD0D /* ButtonColorGradientAnimationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonColorGradientAnimationTests.swift; sourceTree = ""; }; 46 | 49AB0DB42084C8C900F4FD0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 49AB0DB92084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ButtonColorGradientAnimationUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 49AB0DBD2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonColorGradientAnimationUITests.swift; sourceTree = ""; }; 49 | 49AB0DBF2084C8CA00F4FD0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 49AB0D972084C8C700F4FD0D /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | 49AB0DAB2084C8C900F4FD0D /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 49AB0DB62084C8CA00F4FD0D /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 49AB0D912084C8C700F4FD0D = { 78 | isa = PBXGroup; 79 | children = ( 80 | 49AB0D9C2084C8C700F4FD0D /* ButtonColorGradientAnimation */, 81 | 49AB0DB12084C8C900F4FD0D /* ButtonColorGradientAnimationTests */, 82 | 49AB0DBC2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests */, 83 | 49AB0D9B2084C8C700F4FD0D /* Products */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 49AB0D9B2084C8C700F4FD0D /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 49AB0D9A2084C8C700F4FD0D /* ButtonColorGradientAnimation.app */, 91 | 49AB0DAE2084C8C900F4FD0D /* ButtonColorGradientAnimationTests.xctest */, 92 | 49AB0DB92084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.xctest */, 93 | ); 94 | name = Products; 95 | sourceTree = ""; 96 | }; 97 | 49AB0D9C2084C8C700F4FD0D /* ButtonColorGradientAnimation */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 49AB0D9D2084C8C700F4FD0D /* AppDelegate.swift */, 101 | 49AB0D9F2084C8C700F4FD0D /* ViewController.swift */, 102 | 49AB0DA12084C8C700F4FD0D /* Main.storyboard */, 103 | 49AB0DA42084C8C900F4FD0D /* Assets.xcassets */, 104 | 49AB0DA62084C8C900F4FD0D /* LaunchScreen.storyboard */, 105 | 49AB0DA92084C8C900F4FD0D /* Info.plist */, 106 | ); 107 | path = ButtonColorGradientAnimation; 108 | sourceTree = ""; 109 | }; 110 | 49AB0DB12084C8C900F4FD0D /* ButtonColorGradientAnimationTests */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 49AB0DB22084C8C900F4FD0D /* ButtonColorGradientAnimationTests.swift */, 114 | 49AB0DB42084C8C900F4FD0D /* Info.plist */, 115 | ); 116 | path = ButtonColorGradientAnimationTests; 117 | sourceTree = ""; 118 | }; 119 | 49AB0DBC2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 49AB0DBD2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.swift */, 123 | 49AB0DBF2084C8CA00F4FD0D /* Info.plist */, 124 | ); 125 | path = ButtonColorGradientAnimationUITests; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 49AB0D992084C8C700F4FD0D /* ButtonColorGradientAnimation */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 49AB0DC22084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimation" */; 134 | buildPhases = ( 135 | 49AB0D962084C8C700F4FD0D /* Sources */, 136 | 49AB0D972084C8C700F4FD0D /* Frameworks */, 137 | 49AB0D982084C8C700F4FD0D /* Resources */, 138 | ); 139 | buildRules = ( 140 | ); 141 | dependencies = ( 142 | ); 143 | name = ButtonColorGradientAnimation; 144 | productName = ButtonColorGradientAnimation; 145 | productReference = 49AB0D9A2084C8C700F4FD0D /* ButtonColorGradientAnimation.app */; 146 | productType = "com.apple.product-type.application"; 147 | }; 148 | 49AB0DAD2084C8C900F4FD0D /* ButtonColorGradientAnimationTests */ = { 149 | isa = PBXNativeTarget; 150 | buildConfigurationList = 49AB0DC52084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimationTests" */; 151 | buildPhases = ( 152 | 49AB0DAA2084C8C900F4FD0D /* Sources */, 153 | 49AB0DAB2084C8C900F4FD0D /* Frameworks */, 154 | 49AB0DAC2084C8C900F4FD0D /* Resources */, 155 | ); 156 | buildRules = ( 157 | ); 158 | dependencies = ( 159 | 49AB0DB02084C8C900F4FD0D /* PBXTargetDependency */, 160 | ); 161 | name = ButtonColorGradientAnimationTests; 162 | productName = ButtonColorGradientAnimationTests; 163 | productReference = 49AB0DAE2084C8C900F4FD0D /* ButtonColorGradientAnimationTests.xctest */; 164 | productType = "com.apple.product-type.bundle.unit-test"; 165 | }; 166 | 49AB0DB82084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests */ = { 167 | isa = PBXNativeTarget; 168 | buildConfigurationList = 49AB0DC82084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimationUITests" */; 169 | buildPhases = ( 170 | 49AB0DB52084C8CA00F4FD0D /* Sources */, 171 | 49AB0DB62084C8CA00F4FD0D /* Frameworks */, 172 | 49AB0DB72084C8CA00F4FD0D /* Resources */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | 49AB0DBB2084C8CA00F4FD0D /* PBXTargetDependency */, 178 | ); 179 | name = ButtonColorGradientAnimationUITests; 180 | productName = ButtonColorGradientAnimationUITests; 181 | productReference = 49AB0DB92084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.xctest */; 182 | productType = "com.apple.product-type.bundle.ui-testing"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | 49AB0D922084C8C700F4FD0D /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastSwiftUpdateCheck = 0930; 191 | LastUpgradeCheck = 0930; 192 | ORGANIZATIONNAME = ls; 193 | TargetAttributes = { 194 | 49AB0D992084C8C700F4FD0D = { 195 | CreatedOnToolsVersion = 9.3; 196 | }; 197 | 49AB0DAD2084C8C900F4FD0D = { 198 | CreatedOnToolsVersion = 9.3; 199 | TestTargetID = 49AB0D992084C8C700F4FD0D; 200 | }; 201 | 49AB0DB82084C8CA00F4FD0D = { 202 | CreatedOnToolsVersion = 9.3; 203 | TestTargetID = 49AB0D992084C8C700F4FD0D; 204 | }; 205 | }; 206 | }; 207 | buildConfigurationList = 49AB0D952084C8C700F4FD0D /* Build configuration list for PBXProject "ButtonColorGradientAnimation" */; 208 | compatibilityVersion = "Xcode 9.3"; 209 | developmentRegion = en; 210 | hasScannedForEncodings = 0; 211 | knownRegions = ( 212 | en, 213 | Base, 214 | ); 215 | mainGroup = 49AB0D912084C8C700F4FD0D; 216 | productRefGroup = 49AB0D9B2084C8C700F4FD0D /* Products */; 217 | projectDirPath = ""; 218 | projectRoot = ""; 219 | targets = ( 220 | 49AB0D992084C8C700F4FD0D /* ButtonColorGradientAnimation */, 221 | 49AB0DAD2084C8C900F4FD0D /* ButtonColorGradientAnimationTests */, 222 | 49AB0DB82084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests */, 223 | ); 224 | }; 225 | /* End PBXProject section */ 226 | 227 | /* Begin PBXResourcesBuildPhase section */ 228 | 49AB0D982084C8C700F4FD0D /* Resources */ = { 229 | isa = PBXResourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 49AB0DA82084C8C900F4FD0D /* LaunchScreen.storyboard in Resources */, 233 | 49AB0DA52084C8C900F4FD0D /* Assets.xcassets in Resources */, 234 | 49AB0DA32084C8C700F4FD0D /* Main.storyboard in Resources */, 235 | ); 236 | runOnlyForDeploymentPostprocessing = 0; 237 | }; 238 | 49AB0DAC2084C8C900F4FD0D /* Resources */ = { 239 | isa = PBXResourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | }; 245 | 49AB0DB72084C8CA00F4FD0D /* Resources */ = { 246 | isa = PBXResourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | /* End PBXResourcesBuildPhase section */ 253 | 254 | /* Begin PBXSourcesBuildPhase section */ 255 | 49AB0D962084C8C700F4FD0D /* Sources */ = { 256 | isa = PBXSourcesBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | 49AB0DA02084C8C700F4FD0D /* ViewController.swift in Sources */, 260 | 49AB0D9E2084C8C700F4FD0D /* AppDelegate.swift in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | 49AB0DAA2084C8C900F4FD0D /* Sources */ = { 265 | isa = PBXSourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | 49AB0DB32084C8C900F4FD0D /* ButtonColorGradientAnimationTests.swift in Sources */, 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | 49AB0DB52084C8CA00F4FD0D /* Sources */ = { 273 | isa = PBXSourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | 49AB0DBE2084C8CA00F4FD0D /* ButtonColorGradientAnimationUITests.swift in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | /* End PBXSourcesBuildPhase section */ 281 | 282 | /* Begin PBXTargetDependency section */ 283 | 49AB0DB02084C8C900F4FD0D /* PBXTargetDependency */ = { 284 | isa = PBXTargetDependency; 285 | target = 49AB0D992084C8C700F4FD0D /* ButtonColorGradientAnimation */; 286 | targetProxy = 49AB0DAF2084C8C900F4FD0D /* PBXContainerItemProxy */; 287 | }; 288 | 49AB0DBB2084C8CA00F4FD0D /* PBXTargetDependency */ = { 289 | isa = PBXTargetDependency; 290 | target = 49AB0D992084C8C700F4FD0D /* ButtonColorGradientAnimation */; 291 | targetProxy = 49AB0DBA2084C8CA00F4FD0D /* PBXContainerItemProxy */; 292 | }; 293 | /* End PBXTargetDependency section */ 294 | 295 | /* Begin PBXVariantGroup section */ 296 | 49AB0DA12084C8C700F4FD0D /* Main.storyboard */ = { 297 | isa = PBXVariantGroup; 298 | children = ( 299 | 49AB0DA22084C8C700F4FD0D /* Base */, 300 | ); 301 | name = Main.storyboard; 302 | sourceTree = ""; 303 | }; 304 | 49AB0DA62084C8C900F4FD0D /* LaunchScreen.storyboard */ = { 305 | isa = PBXVariantGroup; 306 | children = ( 307 | 49AB0DA72084C8C900F4FD0D /* Base */, 308 | ); 309 | name = LaunchScreen.storyboard; 310 | sourceTree = ""; 311 | }; 312 | /* End PBXVariantGroup section */ 313 | 314 | /* Begin XCBuildConfiguration section */ 315 | 49AB0DC02084C8CA00F4FD0D /* Debug */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ALWAYS_SEARCH_USER_PATHS = NO; 319 | CLANG_ANALYZER_NONNULL = YES; 320 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 321 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 322 | CLANG_CXX_LIBRARY = "libc++"; 323 | CLANG_ENABLE_MODULES = YES; 324 | CLANG_ENABLE_OBJC_ARC = YES; 325 | CLANG_ENABLE_OBJC_WEAK = YES; 326 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 327 | CLANG_WARN_BOOL_CONVERSION = YES; 328 | CLANG_WARN_COMMA = YES; 329 | CLANG_WARN_CONSTANT_CONVERSION = YES; 330 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 332 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INFINITE_RECURSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 338 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 339 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 341 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 342 | CLANG_WARN_STRICT_PROTOTYPES = YES; 343 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 344 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | CODE_SIGN_IDENTITY = "iPhone Developer"; 348 | COPY_PHASE_STRIP = NO; 349 | DEBUG_INFORMATION_FORMAT = dwarf; 350 | ENABLE_STRICT_OBJC_MSGSEND = YES; 351 | ENABLE_TESTABILITY = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu11; 353 | GCC_DYNAMIC_NO_PIC = NO; 354 | GCC_NO_COMMON_BLOCKS = YES; 355 | GCC_OPTIMIZATION_LEVEL = 0; 356 | GCC_PREPROCESSOR_DEFINITIONS = ( 357 | "DEBUG=1", 358 | "$(inherited)", 359 | ); 360 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 361 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 362 | GCC_WARN_UNDECLARED_SELECTOR = YES; 363 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 364 | GCC_WARN_UNUSED_FUNCTION = YES; 365 | GCC_WARN_UNUSED_VARIABLE = YES; 366 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 367 | MTL_ENABLE_DEBUG_INFO = YES; 368 | ONLY_ACTIVE_ARCH = YES; 369 | SDKROOT = iphoneos; 370 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 371 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 372 | }; 373 | name = Debug; 374 | }; 375 | 49AB0DC12084C8CA00F4FD0D /* Release */ = { 376 | isa = XCBuildConfiguration; 377 | buildSettings = { 378 | ALWAYS_SEARCH_USER_PATHS = NO; 379 | CLANG_ANALYZER_NONNULL = YES; 380 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 381 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 382 | CLANG_CXX_LIBRARY = "libc++"; 383 | CLANG_ENABLE_MODULES = YES; 384 | CLANG_ENABLE_OBJC_ARC = YES; 385 | CLANG_ENABLE_OBJC_WEAK = YES; 386 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 387 | CLANG_WARN_BOOL_CONVERSION = YES; 388 | CLANG_WARN_COMMA = YES; 389 | CLANG_WARN_CONSTANT_CONVERSION = YES; 390 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 391 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 392 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 393 | CLANG_WARN_EMPTY_BODY = YES; 394 | CLANG_WARN_ENUM_CONVERSION = YES; 395 | CLANG_WARN_INFINITE_RECURSION = YES; 396 | CLANG_WARN_INT_CONVERSION = YES; 397 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 398 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 399 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 400 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 401 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 402 | CLANG_WARN_STRICT_PROTOTYPES = YES; 403 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 404 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 405 | CLANG_WARN_UNREACHABLE_CODE = YES; 406 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 407 | CODE_SIGN_IDENTITY = "iPhone Developer"; 408 | COPY_PHASE_STRIP = NO; 409 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 410 | ENABLE_NS_ASSERTIONS = NO; 411 | ENABLE_STRICT_OBJC_MSGSEND = YES; 412 | GCC_C_LANGUAGE_STANDARD = gnu11; 413 | GCC_NO_COMMON_BLOCKS = YES; 414 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 415 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 416 | GCC_WARN_UNDECLARED_SELECTOR = YES; 417 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 418 | GCC_WARN_UNUSED_FUNCTION = YES; 419 | GCC_WARN_UNUSED_VARIABLE = YES; 420 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 421 | MTL_ENABLE_DEBUG_INFO = NO; 422 | SDKROOT = iphoneos; 423 | SWIFT_COMPILATION_MODE = wholemodule; 424 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 425 | VALIDATE_PRODUCT = YES; 426 | }; 427 | name = Release; 428 | }; 429 | 49AB0DC32084C8CA00F4FD0D /* Debug */ = { 430 | isa = XCBuildConfiguration; 431 | buildSettings = { 432 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 433 | CODE_SIGN_STYLE = Automatic; 434 | DEVELOPMENT_TEAM = LM6MM3RLWX; 435 | INFOPLIST_FILE = ButtonColorGradientAnimation/Info.plist; 436 | LD_RUNPATH_SEARCH_PATHS = ( 437 | "$(inherited)", 438 | "@executable_path/Frameworks", 439 | ); 440 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimation; 441 | PRODUCT_NAME = "$(TARGET_NAME)"; 442 | SWIFT_VERSION = 4.0; 443 | TARGETED_DEVICE_FAMILY = "1,2"; 444 | }; 445 | name = Debug; 446 | }; 447 | 49AB0DC42084C8CA00F4FD0D /* Release */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 451 | CODE_SIGN_STYLE = Automatic; 452 | DEVELOPMENT_TEAM = LM6MM3RLWX; 453 | INFOPLIST_FILE = ButtonColorGradientAnimation/Info.plist; 454 | LD_RUNPATH_SEARCH_PATHS = ( 455 | "$(inherited)", 456 | "@executable_path/Frameworks", 457 | ); 458 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimation; 459 | PRODUCT_NAME = "$(TARGET_NAME)"; 460 | SWIFT_VERSION = 4.0; 461 | TARGETED_DEVICE_FAMILY = "1,2"; 462 | }; 463 | name = Release; 464 | }; 465 | 49AB0DC62084C8CA00F4FD0D /* Debug */ = { 466 | isa = XCBuildConfiguration; 467 | buildSettings = { 468 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 469 | BUNDLE_LOADER = "$(TEST_HOST)"; 470 | CODE_SIGN_STYLE = Automatic; 471 | DEVELOPMENT_TEAM = LM6MM3RLWX; 472 | INFOPLIST_FILE = ButtonColorGradientAnimationTests/Info.plist; 473 | LD_RUNPATH_SEARCH_PATHS = ( 474 | "$(inherited)", 475 | "@executable_path/Frameworks", 476 | "@loader_path/Frameworks", 477 | ); 478 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimationTests; 479 | PRODUCT_NAME = "$(TARGET_NAME)"; 480 | SWIFT_VERSION = 4.0; 481 | TARGETED_DEVICE_FAMILY = "1,2"; 482 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ButtonColorGradientAnimation.app/ButtonColorGradientAnimation"; 483 | }; 484 | name = Debug; 485 | }; 486 | 49AB0DC72084C8CA00F4FD0D /* Release */ = { 487 | isa = XCBuildConfiguration; 488 | buildSettings = { 489 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 490 | BUNDLE_LOADER = "$(TEST_HOST)"; 491 | CODE_SIGN_STYLE = Automatic; 492 | DEVELOPMENT_TEAM = LM6MM3RLWX; 493 | INFOPLIST_FILE = ButtonColorGradientAnimationTests/Info.plist; 494 | LD_RUNPATH_SEARCH_PATHS = ( 495 | "$(inherited)", 496 | "@executable_path/Frameworks", 497 | "@loader_path/Frameworks", 498 | ); 499 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimationTests; 500 | PRODUCT_NAME = "$(TARGET_NAME)"; 501 | SWIFT_VERSION = 4.0; 502 | TARGETED_DEVICE_FAMILY = "1,2"; 503 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ButtonColorGradientAnimation.app/ButtonColorGradientAnimation"; 504 | }; 505 | name = Release; 506 | }; 507 | 49AB0DC92084C8CA00F4FD0D /* Debug */ = { 508 | isa = XCBuildConfiguration; 509 | buildSettings = { 510 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 511 | CODE_SIGN_STYLE = Automatic; 512 | DEVELOPMENT_TEAM = LM6MM3RLWX; 513 | INFOPLIST_FILE = ButtonColorGradientAnimationUITests/Info.plist; 514 | LD_RUNPATH_SEARCH_PATHS = ( 515 | "$(inherited)", 516 | "@executable_path/Frameworks", 517 | "@loader_path/Frameworks", 518 | ); 519 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimationUITests; 520 | PRODUCT_NAME = "$(TARGET_NAME)"; 521 | SWIFT_VERSION = 4.0; 522 | TARGETED_DEVICE_FAMILY = "1,2"; 523 | TEST_TARGET_NAME = ButtonColorGradientAnimation; 524 | }; 525 | name = Debug; 526 | }; 527 | 49AB0DCA2084C8CA00F4FD0D /* Release */ = { 528 | isa = XCBuildConfiguration; 529 | buildSettings = { 530 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 531 | CODE_SIGN_STYLE = Automatic; 532 | DEVELOPMENT_TEAM = LM6MM3RLWX; 533 | INFOPLIST_FILE = ButtonColorGradientAnimationUITests/Info.plist; 534 | LD_RUNPATH_SEARCH_PATHS = ( 535 | "$(inherited)", 536 | "@executable_path/Frameworks", 537 | "@loader_path/Frameworks", 538 | ); 539 | PRODUCT_BUNDLE_IDENTIFIER = com.ButtonColorGradientAnimationUITests; 540 | PRODUCT_NAME = "$(TARGET_NAME)"; 541 | SWIFT_VERSION = 4.0; 542 | TARGETED_DEVICE_FAMILY = "1,2"; 543 | TEST_TARGET_NAME = ButtonColorGradientAnimation; 544 | }; 545 | name = Release; 546 | }; 547 | /* End XCBuildConfiguration section */ 548 | 549 | /* Begin XCConfigurationList section */ 550 | 49AB0D952084C8C700F4FD0D /* Build configuration list for PBXProject "ButtonColorGradientAnimation" */ = { 551 | isa = XCConfigurationList; 552 | buildConfigurations = ( 553 | 49AB0DC02084C8CA00F4FD0D /* Debug */, 554 | 49AB0DC12084C8CA00F4FD0D /* Release */, 555 | ); 556 | defaultConfigurationIsVisible = 0; 557 | defaultConfigurationName = Release; 558 | }; 559 | 49AB0DC22084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimation" */ = { 560 | isa = XCConfigurationList; 561 | buildConfigurations = ( 562 | 49AB0DC32084C8CA00F4FD0D /* Debug */, 563 | 49AB0DC42084C8CA00F4FD0D /* Release */, 564 | ); 565 | defaultConfigurationIsVisible = 0; 566 | defaultConfigurationName = Release; 567 | }; 568 | 49AB0DC52084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimationTests" */ = { 569 | isa = XCConfigurationList; 570 | buildConfigurations = ( 571 | 49AB0DC62084C8CA00F4FD0D /* Debug */, 572 | 49AB0DC72084C8CA00F4FD0D /* Release */, 573 | ); 574 | defaultConfigurationIsVisible = 0; 575 | defaultConfigurationName = Release; 576 | }; 577 | 49AB0DC82084C8CA00F4FD0D /* Build configuration list for PBXNativeTarget "ButtonColorGradientAnimationUITests" */ = { 578 | isa = XCConfigurationList; 579 | buildConfigurations = ( 580 | 49AB0DC92084C8CA00F4FD0D /* Debug */, 581 | 49AB0DCA2084C8CA00F4FD0D /* Release */, 582 | ); 583 | defaultConfigurationIsVisible = 0; 584 | defaultConfigurationName = Release; 585 | }; 586 | /* End XCConfigurationList section */ 587 | }; 588 | rootObject = 49AB0D922084C8C700F4FD0D /* Project object */; 589 | } 590 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation.xcodeproj/project.xcworkspace/xcuserdata/ls.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LSnumber1/ButtonColorGradientAnimation/bb5074def38bea3e52ac4fab8cf92ba439c13230/ButtonColorGradientAnimation.xcodeproj/project.xcworkspace/xcuserdata/ls.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ButtonColorGradientAnimation.xcodeproj/xcuserdata/ls.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ButtonColorGradientAnimation.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ButtonColorGradientAnimation 4 | // 5 | // Created by ls on 2018/4/16. 6 | // Copyright © 2018年 ls. 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 invalidate graphics rendering callbacks. 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 active 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 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/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 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/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 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimation/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ButtonColorGradientAnimation 4 | // 5 | // Created by ls on 2018/4/16. 6 | // Copyright © 2018年 ls. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var colorButton: UIButton! 14 | var progress: CGFloat = 0.0 //用于控制显示动画次数哦 15 | var caGradientLayer: CAGradientLayer? //渐变色实现 16 | var startColors:[Any]? //动画处使用,动画开始颜色组 17 | var endColors:[Any]? //动画处使用,动画结束颜色组 18 | let colors = [ 19 | UIColor.init(red: 162/255, green: 94/255, blue: 255/255, alpha: 1).cgColor, 20 | UIColor.init(red: 108/255, green: 153/255, blue: 255/255, alpha: 1).cgColor, 21 | UIColor.init(red: 105/255, green: 201/255, blue: 255/255, alpha: 1).cgColor, 22 | UIColor.init(red: 102/255, green: 235/255, blue: 221/255, alpha: 1).cgColor, 23 | UIColor.init(red: 103/255, green: 249/255, blue: 145/255, alpha: 1).cgColor, 24 | UIColor.init(red: 228/255, green: 250/255, blue: 139/255, alpha: 1).cgColor, 25 | UIColor.init(red: 255/255, green: 198/255, blue: 88/255, alpha: 1).cgColor, 26 | UIColor.init(red: 255/255, green: 120/255, blue: 102/255, alpha: 1).cgColor, 27 | UIColor.init(red: 162/255, green: 94/255, blue: 255/255, alpha: 1).cgColor 28 | ] 29 | override func viewDidLoad() { 30 | super.viewDidLoad() 31 | colorButton.layer.cornerRadius = 10 32 | initGradientLayerView() 33 | } 34 | } 35 | //MARK: - CAAnimationDelegate 36 | extension ViewController: CAAnimationDelegate { 37 | func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { 38 | 39 | caGradientLayer?.colors = endColors 40 | gradientAnimation() 41 | progress += 1.0 42 | if Int(progress + 2) >= colors.count { 43 | progress = 0 44 | } 45 | } 46 | } 47 | //MARK: - UI 48 | extension ViewController { 49 | ///初始化CAGradientLayer 50 | func initGradientLayerView() { 51 | caGradientLayer = CAGradientLayer() 52 | caGradientLayer?.frame = CGRect(x: 0, y: 0, width: 200, height: 50) 53 | caGradientLayer?.cornerRadius = 10 54 | caGradientLayer?.startPoint = CGPoint(x: 0, y: 0) 55 | caGradientLayer?.endPoint = CGPoint(x: 1, y: 0) 56 | let colors2 = [ 57 | colors[0], 58 | colors[1] 59 | ] 60 | caGradientLayer?.colors = colors2 61 | startColors = colors2 62 | //Button上添加Layer 63 | colorButton.layer.addSublayer(caGradientLayer!) 64 | //开始动画 65 | self.gradientAnimation() 66 | } 67 | } 68 | //MARK: - 动画 69 | extension ViewController { 70 | ///Layer动画 71 | @objc func gradientAnimation() { 72 | var colorArray = caGradientLayer?.colors 73 | 74 | if endColors != nil { 75 | startColors = endColors 76 | } 77 | colorArray?.removeFirst() 78 | colorArray?.append(colors[Int(progress) + 2]) 79 | endColors = colorArray 80 | let animation = CABasicAnimation(keyPath: "colors") 81 | animation.fromValue = startColors 82 | animation.toValue = endColors 83 | animation.duration = 1 84 | animation.fillMode = kCAFillModeForwards 85 | animation.isRemovedOnCompletion = false 86 | animation.delegate = self 87 | caGradientLayer?.add(animation, forKey: "animateGradient") 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimationTests/ButtonColorGradientAnimationTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonColorGradientAnimationTests.swift 3 | // ButtonColorGradientAnimationTests 4 | // 5 | // Created by ls on 2018/4/16. 6 | // Copyright © 2018年 ls. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ButtonColorGradientAnimation 11 | 12 | class ButtonColorGradientAnimationTests: 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 | // Use XCTAssert and related functions to verify your tests produce the correct results. 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 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimationTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimationUITests/ButtonColorGradientAnimationUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonColorGradientAnimationUITests.swift 3 | // ButtonColorGradientAnimationUITests 4 | // 5 | // Created by ls on 2018/4/16. 6 | // Copyright © 2018年 ls. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class ButtonColorGradientAnimationUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ButtonColorGradientAnimationUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ButtonColorGradientAnimation 2 | 按钮的背景色动画渐变 3 | 效果图如下 4 | 5 | ![image](https://github.com/LSnumber1/ButtonColorGradientAnimation/blob/master/pre.gif) 6 | -------------------------------------------------------------------------------- /pre.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LSnumber1/ButtonColorGradientAnimation/bb5074def38bea3e52ac4fab8cf92ba439c13230/pre.gif --------------------------------------------------------------------------------