├── CustomButton.gif ├── CustomButton.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── Tung.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── CustomButton.xcscheme │ └── xcschememanagement.plist ├── CustomButton ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── icon_name.imageset │ │ ├── Contents.json │ │ ├── stop.png │ │ └── stop1.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Extension │ ├── UIButton+FamAnimation.swift │ ├── UIButton+MagnificationAnimation.swift │ ├── UIButton+PressAnimation.swift │ └── UIButton+SelectionAnimation.swift ├── Info.plist └── ViewController.swift └── README.md /CustomButton.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungfam/ButtonSelectionAnimation/7dab757e1b1927993258f93bce2dc1d2931f14b6/CustomButton.gif -------------------------------------------------------------------------------- /CustomButton.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A612D9EA1E20EB2D008920FB /* UIButton+PressAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A612D9E91E20EB2D008920FB /* UIButton+PressAnimation.swift */; }; 11 | A612D9EC1E20F017008920FB /* UIButton+MagnificationAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A612D9EB1E20F017008920FB /* UIButton+MagnificationAnimation.swift */; }; 12 | A612D9EE1E210120008920FB /* UIButton+FamAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A612D9ED1E210120008920FB /* UIButton+FamAnimation.swift */; }; 13 | A62B69071E1FBF240095E852 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A62B69061E1FBF240095E852 /* AppDelegate.swift */; }; 14 | A62B69091E1FBF240095E852 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A62B69081E1FBF240095E852 /* ViewController.swift */; }; 15 | A62B690C1E1FBF240095E852 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A62B690A1E1FBF240095E852 /* Main.storyboard */; }; 16 | A62B690E1E1FBF240095E852 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A62B690D1E1FBF240095E852 /* Assets.xcassets */; }; 17 | A62B69111E1FBF240095E852 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A62B690F1E1FBF240095E852 /* LaunchScreen.storyboard */; }; 18 | A62B691C1E1FC1BE0095E852 /* UIButton+SelectionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A62B691B1E1FC1BE0095E852 /* UIButton+SelectionAnimation.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | A612D9E91E20EB2D008920FB /* UIButton+PressAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+PressAnimation.swift"; sourceTree = ""; }; 23 | A612D9EB1E20F017008920FB /* UIButton+MagnificationAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+MagnificationAnimation.swift"; sourceTree = ""; }; 24 | A612D9ED1E210120008920FB /* UIButton+FamAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+FamAnimation.swift"; sourceTree = ""; }; 25 | A62B69031E1FBF240095E852 /* CustomButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CustomButton.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | A62B69061E1FBF240095E852 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | A62B69081E1FBF240095E852 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 28 | A62B690B1E1FBF240095E852 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | A62B690D1E1FBF240095E852 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | A62B69101E1FBF240095E852 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | A62B69121E1FBF240095E852 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | A62B691B1E1FC1BE0095E852 /* UIButton+SelectionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+SelectionAnimation.swift"; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | A62B69001E1FBF240095E852 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | A62B68FA1E1FBF240095E852 = { 47 | isa = PBXGroup; 48 | children = ( 49 | A62B69051E1FBF240095E852 /* CustomButton */, 50 | A62B69041E1FBF240095E852 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | A62B69041E1FBF240095E852 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | A62B69031E1FBF240095E852 /* CustomButton.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | A62B69051E1FBF240095E852 /* CustomButton */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | A62B69061E1FBF240095E852 /* AppDelegate.swift */, 66 | A62B69081E1FBF240095E852 /* ViewController.swift */, 67 | A62B691A1E1FC1BE0095E852 /* Extension */, 68 | A62B690A1E1FBF240095E852 /* Main.storyboard */, 69 | A62B690D1E1FBF240095E852 /* Assets.xcassets */, 70 | A62B690F1E1FBF240095E852 /* LaunchScreen.storyboard */, 71 | A62B69121E1FBF240095E852 /* Info.plist */, 72 | ); 73 | path = CustomButton; 74 | sourceTree = ""; 75 | }; 76 | A62B691A1E1FC1BE0095E852 /* Extension */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | A62B691B1E1FC1BE0095E852 /* UIButton+SelectionAnimation.swift */, 80 | A612D9E91E20EB2D008920FB /* UIButton+PressAnimation.swift */, 81 | A612D9EB1E20F017008920FB /* UIButton+MagnificationAnimation.swift */, 82 | A612D9ED1E210120008920FB /* UIButton+FamAnimation.swift */, 83 | ); 84 | path = Extension; 85 | sourceTree = ""; 86 | }; 87 | /* End PBXGroup section */ 88 | 89 | /* Begin PBXNativeTarget section */ 90 | A62B69021E1FBF240095E852 /* CustomButton */ = { 91 | isa = PBXNativeTarget; 92 | buildConfigurationList = A62B69151E1FBF240095E852 /* Build configuration list for PBXNativeTarget "CustomButton" */; 93 | buildPhases = ( 94 | A62B68FF1E1FBF240095E852 /* Sources */, 95 | A62B69001E1FBF240095E852 /* Frameworks */, 96 | A62B69011E1FBF240095E852 /* Resources */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = CustomButton; 103 | productName = CustomButton; 104 | productReference = A62B69031E1FBF240095E852 /* CustomButton.app */; 105 | productType = "com.apple.product-type.application"; 106 | }; 107 | /* End PBXNativeTarget section */ 108 | 109 | /* Begin PBXProject section */ 110 | A62B68FB1E1FBF240095E852 /* Project object */ = { 111 | isa = PBXProject; 112 | attributes = { 113 | LastSwiftUpdateCheck = 0820; 114 | LastUpgradeCheck = 0820; 115 | ORGANIZATIONNAME = "Tung Fam"; 116 | TargetAttributes = { 117 | A62B69021E1FBF240095E852 = { 118 | CreatedOnToolsVersion = 8.2.1; 119 | DevelopmentTeam = RRM459U248; 120 | ProvisioningStyle = Automatic; 121 | }; 122 | }; 123 | }; 124 | buildConfigurationList = A62B68FE1E1FBF240095E852 /* Build configuration list for PBXProject "CustomButton" */; 125 | compatibilityVersion = "Xcode 3.2"; 126 | developmentRegion = English; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | Base, 131 | ); 132 | mainGroup = A62B68FA1E1FBF240095E852; 133 | productRefGroup = A62B69041E1FBF240095E852 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | A62B69021E1FBF240095E852 /* CustomButton */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXResourcesBuildPhase section */ 143 | A62B69011E1FBF240095E852 /* Resources */ = { 144 | isa = PBXResourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | A62B69111E1FBF240095E852 /* LaunchScreen.storyboard in Resources */, 148 | A62B690E1E1FBF240095E852 /* Assets.xcassets in Resources */, 149 | A62B690C1E1FBF240095E852 /* Main.storyboard in Resources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXResourcesBuildPhase section */ 154 | 155 | /* Begin PBXSourcesBuildPhase section */ 156 | A62B68FF1E1FBF240095E852 /* Sources */ = { 157 | isa = PBXSourcesBuildPhase; 158 | buildActionMask = 2147483647; 159 | files = ( 160 | A612D9EC1E20F017008920FB /* UIButton+MagnificationAnimation.swift in Sources */, 161 | A62B69091E1FBF240095E852 /* ViewController.swift in Sources */, 162 | A62B691C1E1FC1BE0095E852 /* UIButton+SelectionAnimation.swift in Sources */, 163 | A612D9EE1E210120008920FB /* UIButton+FamAnimation.swift in Sources */, 164 | A612D9EA1E20EB2D008920FB /* UIButton+PressAnimation.swift in Sources */, 165 | A62B69071E1FBF240095E852 /* AppDelegate.swift in Sources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXSourcesBuildPhase section */ 170 | 171 | /* Begin PBXVariantGroup section */ 172 | A62B690A1E1FBF240095E852 /* Main.storyboard */ = { 173 | isa = PBXVariantGroup; 174 | children = ( 175 | A62B690B1E1FBF240095E852 /* Base */, 176 | ); 177 | name = Main.storyboard; 178 | sourceTree = ""; 179 | }; 180 | A62B690F1E1FBF240095E852 /* LaunchScreen.storyboard */ = { 181 | isa = PBXVariantGroup; 182 | children = ( 183 | A62B69101E1FBF240095E852 /* Base */, 184 | ); 185 | name = LaunchScreen.storyboard; 186 | sourceTree = ""; 187 | }; 188 | /* End PBXVariantGroup section */ 189 | 190 | /* Begin XCBuildConfiguration section */ 191 | A62B69131E1FBF240095E852 /* Debug */ = { 192 | isa = XCBuildConfiguration; 193 | buildSettings = { 194 | ALWAYS_SEARCH_USER_PATHS = NO; 195 | CLANG_ANALYZER_NONNULL = YES; 196 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 197 | CLANG_CXX_LIBRARY = "libc++"; 198 | CLANG_ENABLE_MODULES = YES; 199 | CLANG_ENABLE_OBJC_ARC = YES; 200 | CLANG_WARN_BOOL_CONVERSION = YES; 201 | CLANG_WARN_CONSTANT_CONVERSION = YES; 202 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 203 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 204 | CLANG_WARN_EMPTY_BODY = YES; 205 | CLANG_WARN_ENUM_CONVERSION = YES; 206 | CLANG_WARN_INFINITE_RECURSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 210 | CLANG_WARN_UNREACHABLE_CODE = YES; 211 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 212 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 213 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu99; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 232 | MTL_ENABLE_DEBUG_INFO = YES; 233 | ONLY_ACTIVE_ARCH = YES; 234 | SDKROOT = iphoneos; 235 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 236 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 237 | TARGETED_DEVICE_FAMILY = "1,2"; 238 | }; 239 | name = Debug; 240 | }; 241 | A62B69141E1FBF240095E852 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BOOL_CONVERSION = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 254 | CLANG_WARN_EMPTY_BODY = YES; 255 | CLANG_WARN_ENUM_CONVERSION = YES; 256 | CLANG_WARN_INFINITE_RECURSION = YES; 257 | CLANG_WARN_INT_CONVERSION = YES; 258 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 259 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 265 | ENABLE_NS_ASSERTIONS = NO; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | GCC_C_LANGUAGE_STANDARD = gnu99; 268 | GCC_NO_COMMON_BLOCKS = YES; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 276 | MTL_ENABLE_DEBUG_INFO = NO; 277 | SDKROOT = iphoneos; 278 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 279 | TARGETED_DEVICE_FAMILY = "1,2"; 280 | VALIDATE_PRODUCT = YES; 281 | }; 282 | name = Release; 283 | }; 284 | A62B69161E1FBF240095E852 /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 288 | DEVELOPMENT_TEAM = RRM459U248; 289 | INFOPLIST_FILE = CustomButton/Info.plist; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = com.TungFam.CustomButton; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | SWIFT_VERSION = 3.0; 294 | }; 295 | name = Debug; 296 | }; 297 | A62B69171E1FBF240095E852 /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | DEVELOPMENT_TEAM = RRM459U248; 302 | INFOPLIST_FILE = CustomButton/Info.plist; 303 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 304 | PRODUCT_BUNDLE_IDENTIFIER = com.TungFam.CustomButton; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | SWIFT_VERSION = 3.0; 307 | }; 308 | name = Release; 309 | }; 310 | /* End XCBuildConfiguration section */ 311 | 312 | /* Begin XCConfigurationList section */ 313 | A62B68FE1E1FBF240095E852 /* Build configuration list for PBXProject "CustomButton" */ = { 314 | isa = XCConfigurationList; 315 | buildConfigurations = ( 316 | A62B69131E1FBF240095E852 /* Debug */, 317 | A62B69141E1FBF240095E852 /* Release */, 318 | ); 319 | defaultConfigurationIsVisible = 0; 320 | defaultConfigurationName = Release; 321 | }; 322 | A62B69151E1FBF240095E852 /* Build configuration list for PBXNativeTarget "CustomButton" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | A62B69161E1FBF240095E852 /* Debug */, 326 | A62B69171E1FBF240095E852 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | /* End XCConfigurationList section */ 332 | }; 333 | rootObject = A62B68FB1E1FBF240095E852 /* Project object */; 334 | } 335 | -------------------------------------------------------------------------------- /CustomButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomButton.xcodeproj/xcuserdata/Tung.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CustomButton.xcodeproj/xcuserdata/Tung.xcuserdatad/xcschemes/CustomButton.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CustomButton.xcodeproj/xcuserdata/Tung.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CustomButton.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A62B69021E1FBF240095E852 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CustomButton/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/6/17. 6 | // Copyright © 2017 Tung Fam. 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 | -------------------------------------------------------------------------------- /CustomButton/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 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /CustomButton/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CustomButton/Assets.xcassets/icon_name.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "stop.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "stop1.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /CustomButton/Assets.xcassets/icon_name.imageset/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungfam/ButtonSelectionAnimation/7dab757e1b1927993258f93bce2dc1d2931f14b6/CustomButton/Assets.xcassets/icon_name.imageset/stop.png -------------------------------------------------------------------------------- /CustomButton/Assets.xcassets/icon_name.imageset/stop1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungfam/ButtonSelectionAnimation/7dab757e1b1927993258f93bce2dc1d2931f14b6/CustomButton/Assets.xcassets/icon_name.imageset/stop1.png -------------------------------------------------------------------------------- /CustomButton/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 | 27 | 28 | -------------------------------------------------------------------------------- /CustomButton/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 | 31 | 37 | 43 | 49 | 55 | 61 | 67 | 73 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /CustomButton/Extension/UIButton+FamAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+FamAnimation.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/7/17. 6 | // Copyright © 2017 Tung Fam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UIButton_FamAnimation: UIButton { 12 | // FAM stands for Fade-out And Magnification 13 | 14 | let selectionDuration = 0.2 15 | var aSelected = false 16 | 17 | func setSelected(_ selected: Bool, withAnimation: Bool) { 18 | if withAnimation { 19 | self.aSelected = selected 20 | 21 | if selected { 22 | selectionAnimation() 23 | } else { 24 | unselectionAnimation() 25 | } 26 | } else { 27 | /* usual selection without animation */ 28 | self.isSelected = selected 29 | } 30 | 31 | } 32 | 33 | private func selectionAnimation() { 34 | UIView.animate(withDuration: self.selectionDuration, animations: { 35 | self.alpha = 0.0 36 | self.transform = CGAffineTransform(scaleX: 0.0001, y: 0.0001) 37 | }) { (finished) in 38 | self.isSelected = self.aSelected 39 | UIView.animate(withDuration: self.selectionDuration, animations: { 40 | self.transform = CGAffineTransform(scaleX: 1.5, y: 1.5) 41 | self.alpha = 1.0 42 | }) { (finished) in 43 | UIView.animate(withDuration: self.selectionDuration, animations: { 44 | self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) 45 | }) 46 | } 47 | } 48 | } 49 | 50 | private func unselectionAnimation() { 51 | self.isSelected = self.aSelected 52 | UIView.animate(withDuration: self.selectionDuration, animations: { 53 | self.transform = CGAffineTransform(scaleX: 1.5, y: 1.5) 54 | }) { (finished) in 55 | UIView.animate(withDuration: self.selectionDuration, animations: { 56 | self.transform = CGAffineTransform(scaleX: 0.0001, y: 0.0001) 57 | self.alpha = 0.0 58 | }) { (finished) in 59 | UIView.animate(withDuration: self.selectionDuration, animations: { 60 | self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) 61 | self.alpha = 1.0 62 | }) 63 | } 64 | } 65 | } 66 | 67 | func setDefaultImage(withName imageName: String) { 68 | if let image = UIImage(named: imageName) { 69 | self.setImage(image, for: .normal) 70 | } 71 | } 72 | 73 | func setSelectedImage(withName imageName: String, withColor color: UIColor) { 74 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 75 | self.setImage(image, for: .selected) 76 | self.tintColor = color 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /CustomButton/Extension/UIButton+MagnificationAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+MagnificationAnimation.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/7/17. 6 | // Copyright © 2017 Tung Fam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UIButton_MagnificationAnimation: UIButton { 12 | 13 | let magnificationDuration = 0.1 14 | 15 | func magnifyOnPress(_ animate: Bool) { 16 | if animate { 17 | self.addTarget(self, action: #selector(self.magnifyAnimation), for: .touchDown) 18 | self.addTarget(self, action: #selector(self.unmagnifyAnimation), for: .touchUpInside) 19 | } 20 | } 21 | 22 | @objc private func magnifyAnimation() { 23 | UIView.animate(withDuration: self.magnificationDuration, animations: { 24 | self.transform = CGAffineTransform(scaleX: 1.15, y: 1.15) 25 | }) 26 | } 27 | 28 | @objc private func unmagnifyAnimation() { 29 | UIView.animate(withDuration: self.magnificationDuration, animations: { 30 | self.transform = CGAffineTransform(scaleX: 1, y: 1) 31 | }) 32 | } 33 | 34 | func setDefaultImage(withName imageName: String) { 35 | if let image = UIImage(named: imageName) { 36 | self.setImage(image, for: .normal) 37 | } 38 | } 39 | 40 | func setSelectedImage(withName imageName: String, withColor color: UIColor) { 41 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 42 | self.setImage(image, for: .selected) 43 | self.tintColor = color 44 | } 45 | 46 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 47 | self.setImage(image, for: .highlighted) 48 | self.tintColor = color 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CustomButton/Extension/UIButton+PressAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+PressAnimation.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/7/17. 6 | // Copyright © 2017 Tung Fam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UIButton_PressAnimation: UIButton { 12 | 13 | let pressDuration = 0.1 14 | 15 | func animateOnPress(_ animate: Bool) { 16 | if animate { 17 | self.addTarget(self, action: #selector(self.pressAnimation), for: .touchDown) 18 | self.addTarget(self, action: #selector(self.unpressAnimation), for: .touchUpInside) 19 | } 20 | } 21 | 22 | @objc private func pressAnimation() { 23 | UIView.animate(withDuration: self.pressDuration, animations: { 24 | self.transform = CGAffineTransform(scaleX: 0.85, y: 0.85) 25 | }) 26 | } 27 | 28 | @objc private func unpressAnimation() { 29 | UIView.animate(withDuration: self.pressDuration, animations: { 30 | self.transform = CGAffineTransform(scaleX: 1, y: 1) 31 | }) 32 | } 33 | 34 | func setDefaultImage(withName imageName: String) { 35 | if let image = UIImage(named: imageName) { 36 | self.setImage(image, for: .normal) 37 | } 38 | } 39 | 40 | func setSelectedImage(withName imageName: String, withColor color: UIColor) { 41 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 42 | self.setImage(image, for: .selected) 43 | self.tintColor = color 44 | } 45 | 46 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 47 | self.setImage(image, for: .highlighted) 48 | self.tintColor = color 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CustomButton/Extension/UIButton+SelectionAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+SelectionAnimation.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/6/17. 6 | // Copyright © 2017 Tung Fam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UIButton_SelectionAnimation: UIButton { 12 | 13 | let selectionDuration = 0.2 14 | 15 | func setSelected(_ selected: Bool, withAnimation: Bool) { 16 | if withAnimation { 17 | self.isSelected = selected 18 | 19 | if selected { 20 | selectionAnimation() 21 | } else { 22 | unselectionAnimation() 23 | } 24 | } else { 25 | /* usual selection without animation */ 26 | self.isSelected = selected 27 | } 28 | 29 | } 30 | 31 | private func selectionAnimation() { 32 | UIView.animate(withDuration: self.selectionDuration, animations: { 33 | self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) 34 | }) { (finished) in 35 | UIView.animate(withDuration: self.selectionDuration, animations: { 36 | self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) 37 | }) 38 | } 39 | } 40 | 41 | private func unselectionAnimation() { 42 | UIView.animate(withDuration: self.selectionDuration, animations: { 43 | self.transform = CGAffineTransform(scaleX: 1.4, y: 1.4) 44 | }) { (finished) in 45 | UIView.animate(withDuration: self.selectionDuration, animations: { 46 | self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) 47 | }) 48 | } 49 | } 50 | 51 | func setDefaultImage(withName imageName: String) { 52 | if let image = UIImage(named: imageName) { 53 | self.setImage(image, for: .normal) 54 | } 55 | } 56 | 57 | func setSelectedImage(withName imageName: String, withColor color: UIColor) { 58 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 59 | self.setImage(image, for: .selected) 60 | self.tintColor = color 61 | } 62 | 63 | if let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate) { 64 | self.setImage(image, for: .highlighted) 65 | self.tintColor = color 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CustomButton/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 | 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 | -------------------------------------------------------------------------------- /CustomButton/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CustomButton 4 | // 5 | // Created by Tung Fam on 1/6/17. 6 | // Copyright © 2017 Tung Fam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var selectionAnimationButton: UIButton_SelectionAnimation! 14 | @IBOutlet weak var pressAnimationButton: UIButton_PressAnimation! 15 | @IBOutlet weak var magnificationAnimationButton: UIButton_MagnificationAnimation! 16 | @IBOutlet weak var famAnimationButton: UIButton_FamAnimation! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | // 1. set up selection animation button 22 | setUpSelectionAnimationButton() 23 | 24 | // 2. set up press animation button 25 | setUpPressAnimationButton() 26 | 27 | // 3. set up magnification animation button 28 | setUpMagnificationAnimationButton() 29 | 30 | // 4. set up fam animation button 31 | setUpFamAnimationButton() 32 | 33 | } 34 | 35 | /* 1. Begin: Selection animation related */ 36 | 37 | func setUpSelectionAnimationButton() { 38 | self.selectionAnimationButton.setDefaultImage(withName: "icon_name") 39 | let selectedColor = UIColor.red 40 | self.selectionAnimationButton.setSelectedImage(withName: "icon_name", withColor: selectedColor) 41 | } 42 | 43 | @IBAction func selectionAnimationButtonAction(_ sender: UIButton_SelectionAnimation) { 44 | let isButtonSelected = self.selectionAnimationButton.isSelected 45 | self.selectionAnimationButton.setSelected(!isButtonSelected, withAnimation: true) 46 | } 47 | 48 | /* 1. End: Selection animation related */ 49 | 50 | 51 | 52 | 53 | /* 2. Begin: Press animation related */ 54 | 55 | func setUpPressAnimationButton() { 56 | self.pressAnimationButton.setDefaultImage(withName: "icon_name") 57 | let selectedColor = UIColor.green 58 | self.pressAnimationButton.setSelectedImage(withName: "icon_name", withColor: selectedColor) 59 | 60 | self.pressAnimationButton.animateOnPress(true) 61 | } 62 | 63 | @IBAction func pressAnimationButtonAction(_ sender: UIButton_PressAnimation) { 64 | self.pressAnimationButton.isSelected = !self.pressAnimationButton.isSelected 65 | } 66 | 67 | /* 2. End: Press animation related */ 68 | 69 | 70 | 71 | 72 | /* 3. Begin: Magnification animation related */ 73 | 74 | func setUpMagnificationAnimationButton() { 75 | self.magnificationAnimationButton.setDefaultImage(withName: "icon_name") 76 | let selectedColor = UIColor.purple 77 | self.magnificationAnimationButton.setSelectedImage(withName: "icon_name", withColor: selectedColor) 78 | 79 | self.magnificationAnimationButton.magnifyOnPress(true) 80 | } 81 | 82 | @IBAction func magnificationAnimationButtonAction(_ sender: UIButton_MagnificationAnimation) { 83 | self.magnificationAnimationButton.isSelected = !self.magnificationAnimationButton.isSelected 84 | } 85 | 86 | /* 3. End: Magnification animation related */ 87 | 88 | 89 | 90 | 91 | /* 4. Begin: FAM (Fade-out and magnification) animation related */ 92 | 93 | func setUpFamAnimationButton() { 94 | self.famAnimationButton.setDefaultImage(withName: "icon_name") 95 | let selectedColor = UIColor.yellow 96 | self.famAnimationButton.setSelectedImage(withName: "icon_name", withColor: selectedColor) 97 | } 98 | 99 | @IBAction func famAnimationButtonAction(_ sender: UIButton_FamAnimation) { 100 | let isButtonSelected = self.famAnimationButton.isSelected 101 | self.famAnimationButton.setSelected(!isButtonSelected, withAnimation: true) 102 | } 103 | 104 | /* 4. End: FAM (Fade-out and magnification) animation related */ 105 | } 106 | 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ButtonSelectionAnimation 2 | UIButton subclass which performs animation on selection. Check it out! 3 | 4 | 5 | 6 | _note: please nevermind the quality of the selected buttons. it looks perfect on iphone or simulator. gif reduces the quality_ 7 | 8 | 9 | ## Description ## 10 | 11 | There are 4 different custom subclusses of UIButton. Hope it will be useful for you. 12 | 13 | ## Usage / Installation ## 14 | 15 | 1. Choose the animation you like. 16 | 2. Clone or Download ButtonSelectionAnimation github repo. 17 | 3. Assign the chosen custom class to the button you want to animate. 18 | Custom classes are located in `Extension` folder. 19 | 4. Check out `ViewController.swift` class to see how to simply implement the animation into your code. 20 | 5. Done! Enjoy the button animation :) 21 | --------------------------------------------------------------------------------