├── LICENSE ├── README.md ├── RMSaveButton.podspec ├── RMSaveButton.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── richardmcduffey.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── richardmcduffey.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── RMSaveButton.xcscheme │ └── xcschememanagement.plist ├── RMSaveButton ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── RMSaveButton.h ├── RMSaveButton.m ├── ViewController.h ├── ViewController.m └── main.m └── RMSaveButtonTests ├── Info.plist └── RMSaveButtonTests.m /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Richard McDuffey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RMSaveButton 2 | A drop-in replacement for a click-to-save action in iOS. 3 | 4 | Inspired by Chad Bercea's Dribbble post [here!](https://dribbble.com/shots/1986686-Button-Confirmation?list=users&offset=0) 5 | 6 | ![alt tag](https://cloud.githubusercontent.com/assets/11640459/7903378/46bfdb1c-07a0-11e5-93d0-13386f18cd18.gif) 7 | 8 | ##Requirements 9 | - iOS 7.0 or later 10 | - Xcode 6.1 11 | 12 | ##Installation 13 | 14 | [Cocoapods](https://cocoapods.org/) 15 | - **pod 'RMSaveButton'** 16 | 17 | Manual 18 | - Add RMSaveButton.h and .m files to project 19 | 20 | ##Usage 21 | Run the demo project for example. 22 | 23 | ##License 24 | RMSaveButton is available under the MIT license. See the LICENSE file for more info. 25 | -------------------------------------------------------------------------------- /RMSaveButton.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "RMSaveButton" 3 | s.version = "0.1.0" 4 | s.summary = "A drop-in replacement for a click-to-save action in iOS.." 5 | s.homepage = "https://github.com/mcduffeyrt/RMSaveButton" 6 | # s.screenshots = "https://cloud.githubusercontent.com/assets/11640459/7904109/c2bbda6c-07b5-11e5-984e-773b680cc9b7.png" 7 | s.license = 'MIT' 8 | s.author = { "Richard McDuffey" => "richard.t.mcduffey@gmail.com" } 9 | s.source = { :git => "https://github.com/mcduffeyrt/RMSaveButton.git", :tag => s.version.to_s } 10 | # s.social_media_url = 'https://twitter.com/mcduff_isdatguy' 11 | 12 | s.platform = :ios, '7.0' 13 | s.requires_arc = true 14 | 15 | s.source_files = 'RMSaveButton/RMSaveButton.{h,m}' 16 | s.resource_bundles = { 17 | 'RMSaveButton' => ['Pod/Assets/*.png'] 18 | } 19 | end 20 | -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F761C5851B1A8F2000144FF0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F761C5841B1A8F2000144FF0 /* main.m */; }; 11 | F761C5881B1A8F2000144FF0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F761C5871B1A8F2000144FF0 /* AppDelegate.m */; }; 12 | F761C58B1B1A8F2000144FF0 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F761C58A1B1A8F2000144FF0 /* ViewController.m */; }; 13 | F761C58E1B1A8F2000144FF0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F761C58C1B1A8F2000144FF0 /* Main.storyboard */; }; 14 | F761C5901B1A8F2000144FF0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F761C58F1B1A8F2000144FF0 /* Images.xcassets */; }; 15 | F761C5931B1A8F2000144FF0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = F761C5911B1A8F2000144FF0 /* LaunchScreen.xib */; }; 16 | F761C59F1B1A8F2000144FF0 /* RMSaveButtonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F761C59E1B1A8F2000144FF0 /* RMSaveButtonTests.m */; }; 17 | F761C5AB1B1A8F9100144FF0 /* RMSaveButton.m in Sources */ = {isa = PBXBuildFile; fileRef = F761C5AA1B1A8F9100144FF0 /* RMSaveButton.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | F761C5991B1A8F2000144FF0 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = F761C5771B1A8F2000144FF0 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = F761C57E1B1A8F2000144FF0; 26 | remoteInfo = RMSaveButton; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | F761C57F1B1A8F2000144FF0 /* RMSaveButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RMSaveButton.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | F761C5831B1A8F2000144FF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | F761C5841B1A8F2000144FF0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | F761C5861B1A8F2000144FF0 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | F761C5871B1A8F2000144FF0 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | F761C5891B1A8F2000144FF0 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | F761C58A1B1A8F2000144FF0 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | F761C58D1B1A8F2000144FF0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | F761C58F1B1A8F2000144FF0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 40 | F761C5921B1A8F2000144FF0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 41 | F761C5981B1A8F2000144FF0 /* RMSaveButtonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RMSaveButtonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | F761C59D1B1A8F2000144FF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | F761C59E1B1A8F2000144FF0 /* RMSaveButtonTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RMSaveButtonTests.m; sourceTree = ""; }; 44 | F761C5A91B1A8F9100144FF0 /* RMSaveButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMSaveButton.h; sourceTree = ""; }; 45 | F761C5AA1B1A8F9100144FF0 /* RMSaveButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMSaveButton.m; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | F761C57C1B1A8F2000144FF0 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | F761C5951B1A8F2000144FF0 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | F761C5761B1A8F2000144FF0 = { 67 | isa = PBXGroup; 68 | children = ( 69 | F761C5811B1A8F2000144FF0 /* RMSaveButton */, 70 | F761C59B1B1A8F2000144FF0 /* RMSaveButtonTests */, 71 | F761C5801B1A8F2000144FF0 /* Products */, 72 | ); 73 | sourceTree = ""; 74 | }; 75 | F761C5801B1A8F2000144FF0 /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | F761C57F1B1A8F2000144FF0 /* RMSaveButton.app */, 79 | F761C5981B1A8F2000144FF0 /* RMSaveButtonTests.xctest */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | F761C5811B1A8F2000144FF0 /* RMSaveButton */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | F761C5A81B1A8F7400144FF0 /* Source */, 88 | F761C5861B1A8F2000144FF0 /* AppDelegate.h */, 89 | F761C5871B1A8F2000144FF0 /* AppDelegate.m */, 90 | F761C5891B1A8F2000144FF0 /* ViewController.h */, 91 | F761C58A1B1A8F2000144FF0 /* ViewController.m */, 92 | F761C58C1B1A8F2000144FF0 /* Main.storyboard */, 93 | F761C58F1B1A8F2000144FF0 /* Images.xcassets */, 94 | F761C5911B1A8F2000144FF0 /* LaunchScreen.xib */, 95 | F761C5821B1A8F2000144FF0 /* Supporting Files */, 96 | ); 97 | path = RMSaveButton; 98 | sourceTree = ""; 99 | }; 100 | F761C5821B1A8F2000144FF0 /* Supporting Files */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | F761C5831B1A8F2000144FF0 /* Info.plist */, 104 | F761C5841B1A8F2000144FF0 /* main.m */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | F761C59B1B1A8F2000144FF0 /* RMSaveButtonTests */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | F761C59E1B1A8F2000144FF0 /* RMSaveButtonTests.m */, 113 | F761C59C1B1A8F2000144FF0 /* Supporting Files */, 114 | ); 115 | path = RMSaveButtonTests; 116 | sourceTree = ""; 117 | }; 118 | F761C59C1B1A8F2000144FF0 /* Supporting Files */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | F761C59D1B1A8F2000144FF0 /* Info.plist */, 122 | ); 123 | name = "Supporting Files"; 124 | sourceTree = ""; 125 | }; 126 | F761C5A81B1A8F7400144FF0 /* Source */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | F761C5A91B1A8F9100144FF0 /* RMSaveButton.h */, 130 | F761C5AA1B1A8F9100144FF0 /* RMSaveButton.m */, 131 | ); 132 | name = Source; 133 | sourceTree = ""; 134 | }; 135 | /* End PBXGroup section */ 136 | 137 | /* Begin PBXNativeTarget section */ 138 | F761C57E1B1A8F2000144FF0 /* RMSaveButton */ = { 139 | isa = PBXNativeTarget; 140 | buildConfigurationList = F761C5A21B1A8F2000144FF0 /* Build configuration list for PBXNativeTarget "RMSaveButton" */; 141 | buildPhases = ( 142 | F761C57B1B1A8F2000144FF0 /* Sources */, 143 | F761C57C1B1A8F2000144FF0 /* Frameworks */, 144 | F761C57D1B1A8F2000144FF0 /* Resources */, 145 | ); 146 | buildRules = ( 147 | ); 148 | dependencies = ( 149 | ); 150 | name = RMSaveButton; 151 | productName = RMSaveButton; 152 | productReference = F761C57F1B1A8F2000144FF0 /* RMSaveButton.app */; 153 | productType = "com.apple.product-type.application"; 154 | }; 155 | F761C5971B1A8F2000144FF0 /* RMSaveButtonTests */ = { 156 | isa = PBXNativeTarget; 157 | buildConfigurationList = F761C5A51B1A8F2000144FF0 /* Build configuration list for PBXNativeTarget "RMSaveButtonTests" */; 158 | buildPhases = ( 159 | F761C5941B1A8F2000144FF0 /* Sources */, 160 | F761C5951B1A8F2000144FF0 /* Frameworks */, 161 | F761C5961B1A8F2000144FF0 /* Resources */, 162 | ); 163 | buildRules = ( 164 | ); 165 | dependencies = ( 166 | F761C59A1B1A8F2000144FF0 /* PBXTargetDependency */, 167 | ); 168 | name = RMSaveButtonTests; 169 | productName = RMSaveButtonTests; 170 | productReference = F761C5981B1A8F2000144FF0 /* RMSaveButtonTests.xctest */; 171 | productType = "com.apple.product-type.bundle.unit-test"; 172 | }; 173 | /* End PBXNativeTarget section */ 174 | 175 | /* Begin PBXProject section */ 176 | F761C5771B1A8F2000144FF0 /* Project object */ = { 177 | isa = PBXProject; 178 | attributes = { 179 | LastUpgradeCheck = 0630; 180 | ORGANIZATIONNAME = "Richard McDuffey"; 181 | TargetAttributes = { 182 | F761C57E1B1A8F2000144FF0 = { 183 | CreatedOnToolsVersion = 6.3.2; 184 | }; 185 | F761C5971B1A8F2000144FF0 = { 186 | CreatedOnToolsVersion = 6.3.2; 187 | TestTargetID = F761C57E1B1A8F2000144FF0; 188 | }; 189 | }; 190 | }; 191 | buildConfigurationList = F761C57A1B1A8F2000144FF0 /* Build configuration list for PBXProject "RMSaveButton" */; 192 | compatibilityVersion = "Xcode 3.2"; 193 | developmentRegion = English; 194 | hasScannedForEncodings = 0; 195 | knownRegions = ( 196 | en, 197 | Base, 198 | ); 199 | mainGroup = F761C5761B1A8F2000144FF0; 200 | productRefGroup = F761C5801B1A8F2000144FF0 /* Products */; 201 | projectDirPath = ""; 202 | projectRoot = ""; 203 | targets = ( 204 | F761C57E1B1A8F2000144FF0 /* RMSaveButton */, 205 | F761C5971B1A8F2000144FF0 /* RMSaveButtonTests */, 206 | ); 207 | }; 208 | /* End PBXProject section */ 209 | 210 | /* Begin PBXResourcesBuildPhase section */ 211 | F761C57D1B1A8F2000144FF0 /* Resources */ = { 212 | isa = PBXResourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | F761C58E1B1A8F2000144FF0 /* Main.storyboard in Resources */, 216 | F761C5931B1A8F2000144FF0 /* LaunchScreen.xib in Resources */, 217 | F761C5901B1A8F2000144FF0 /* Images.xcassets in Resources */, 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | F761C5961B1A8F2000144FF0 /* Resources */ = { 222 | isa = PBXResourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | /* End PBXResourcesBuildPhase section */ 229 | 230 | /* Begin PBXSourcesBuildPhase section */ 231 | F761C57B1B1A8F2000144FF0 /* Sources */ = { 232 | isa = PBXSourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | F761C58B1B1A8F2000144FF0 /* ViewController.m in Sources */, 236 | F761C5881B1A8F2000144FF0 /* AppDelegate.m in Sources */, 237 | F761C5851B1A8F2000144FF0 /* main.m in Sources */, 238 | F761C5AB1B1A8F9100144FF0 /* RMSaveButton.m in Sources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | F761C5941B1A8F2000144FF0 /* Sources */ = { 243 | isa = PBXSourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | F761C59F1B1A8F2000144FF0 /* RMSaveButtonTests.m in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | /* End PBXSourcesBuildPhase section */ 251 | 252 | /* Begin PBXTargetDependency section */ 253 | F761C59A1B1A8F2000144FF0 /* PBXTargetDependency */ = { 254 | isa = PBXTargetDependency; 255 | target = F761C57E1B1A8F2000144FF0 /* RMSaveButton */; 256 | targetProxy = F761C5991B1A8F2000144FF0 /* PBXContainerItemProxy */; 257 | }; 258 | /* End PBXTargetDependency section */ 259 | 260 | /* Begin PBXVariantGroup section */ 261 | F761C58C1B1A8F2000144FF0 /* Main.storyboard */ = { 262 | isa = PBXVariantGroup; 263 | children = ( 264 | F761C58D1B1A8F2000144FF0 /* Base */, 265 | ); 266 | name = Main.storyboard; 267 | sourceTree = ""; 268 | }; 269 | F761C5911B1A8F2000144FF0 /* LaunchScreen.xib */ = { 270 | isa = PBXVariantGroup; 271 | children = ( 272 | F761C5921B1A8F2000144FF0 /* Base */, 273 | ); 274 | name = LaunchScreen.xib; 275 | sourceTree = ""; 276 | }; 277 | /* End PBXVariantGroup section */ 278 | 279 | /* Begin XCBuildConfiguration section */ 280 | F761C5A01B1A8F2000144FF0 /* Debug */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_SEARCH_USER_PATHS = NO; 284 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 285 | CLANG_CXX_LIBRARY = "libc++"; 286 | CLANG_ENABLE_MODULES = YES; 287 | CLANG_ENABLE_OBJC_ARC = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_UNREACHABLE_CODE = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 298 | COPY_PHASE_STRIP = NO; 299 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 300 | ENABLE_STRICT_OBJC_MSGSEND = YES; 301 | GCC_C_LANGUAGE_STANDARD = gnu99; 302 | GCC_DYNAMIC_NO_PIC = NO; 303 | GCC_NO_COMMON_BLOCKS = YES; 304 | GCC_OPTIMIZATION_LEVEL = 0; 305 | GCC_PREPROCESSOR_DEFINITIONS = ( 306 | "DEBUG=1", 307 | "$(inherited)", 308 | ); 309 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 310 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 311 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 312 | GCC_WARN_UNDECLARED_SELECTOR = YES; 313 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 314 | GCC_WARN_UNUSED_FUNCTION = YES; 315 | GCC_WARN_UNUSED_VARIABLE = YES; 316 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 317 | MTL_ENABLE_DEBUG_INFO = YES; 318 | ONLY_ACTIVE_ARCH = YES; 319 | SDKROOT = iphoneos; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | }; 322 | name = Debug; 323 | }; 324 | F761C5A11B1A8F2000144FF0 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 329 | CLANG_CXX_LIBRARY = "libc++"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_WARN_BOOL_CONVERSION = YES; 333 | CLANG_WARN_CONSTANT_CONVERSION = YES; 334 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 335 | CLANG_WARN_EMPTY_BODY = YES; 336 | CLANG_WARN_ENUM_CONVERSION = YES; 337 | CLANG_WARN_INT_CONVERSION = YES; 338 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 339 | CLANG_WARN_UNREACHABLE_CODE = YES; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 342 | COPY_PHASE_STRIP = NO; 343 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 344 | ENABLE_NS_ASSERTIONS = NO; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_NO_COMMON_BLOCKS = YES; 348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 350 | GCC_WARN_UNDECLARED_SELECTOR = YES; 351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_VARIABLE = YES; 354 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 355 | MTL_ENABLE_DEBUG_INFO = NO; 356 | SDKROOT = iphoneos; 357 | TARGETED_DEVICE_FAMILY = "1,2"; 358 | VALIDATE_PRODUCT = YES; 359 | }; 360 | name = Release; 361 | }; 362 | F761C5A31B1A8F2000144FF0 /* Debug */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 366 | INFOPLIST_FILE = RMSaveButton/Info.plist; 367 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 368 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 369 | PRODUCT_NAME = "$(TARGET_NAME)"; 370 | }; 371 | name = Debug; 372 | }; 373 | F761C5A41B1A8F2000144FF0 /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 377 | INFOPLIST_FILE = RMSaveButton/Info.plist; 378 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 379 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 380 | PRODUCT_NAME = "$(TARGET_NAME)"; 381 | }; 382 | name = Release; 383 | }; 384 | F761C5A61B1A8F2000144FF0 /* Debug */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | BUNDLE_LOADER = "$(TEST_HOST)"; 388 | FRAMEWORK_SEARCH_PATHS = ( 389 | "$(SDKROOT)/Developer/Library/Frameworks", 390 | "$(inherited)", 391 | ); 392 | GCC_PREPROCESSOR_DEFINITIONS = ( 393 | "DEBUG=1", 394 | "$(inherited)", 395 | ); 396 | INFOPLIST_FILE = RMSaveButtonTests/Info.plist; 397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RMSaveButton.app/RMSaveButton"; 400 | }; 401 | name = Debug; 402 | }; 403 | F761C5A71B1A8F2000144FF0 /* Release */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | BUNDLE_LOADER = "$(TEST_HOST)"; 407 | FRAMEWORK_SEARCH_PATHS = ( 408 | "$(SDKROOT)/Developer/Library/Frameworks", 409 | "$(inherited)", 410 | ); 411 | INFOPLIST_FILE = RMSaveButtonTests/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RMSaveButton.app/RMSaveButton"; 415 | }; 416 | name = Release; 417 | }; 418 | /* End XCBuildConfiguration section */ 419 | 420 | /* Begin XCConfigurationList section */ 421 | F761C57A1B1A8F2000144FF0 /* Build configuration list for PBXProject "RMSaveButton" */ = { 422 | isa = XCConfigurationList; 423 | buildConfigurations = ( 424 | F761C5A01B1A8F2000144FF0 /* Debug */, 425 | F761C5A11B1A8F2000144FF0 /* Release */, 426 | ); 427 | defaultConfigurationIsVisible = 0; 428 | defaultConfigurationName = Release; 429 | }; 430 | F761C5A21B1A8F2000144FF0 /* Build configuration list for PBXNativeTarget "RMSaveButton" */ = { 431 | isa = XCConfigurationList; 432 | buildConfigurations = ( 433 | F761C5A31B1A8F2000144FF0 /* Debug */, 434 | F761C5A41B1A8F2000144FF0 /* Release */, 435 | ); 436 | defaultConfigurationIsVisible = 0; 437 | }; 438 | F761C5A51B1A8F2000144FF0 /* Build configuration list for PBXNativeTarget "RMSaveButtonTests" */ = { 439 | isa = XCConfigurationList; 440 | buildConfigurations = ( 441 | F761C5A61B1A8F2000144FF0 /* Debug */, 442 | F761C5A71B1A8F2000144FF0 /* Release */, 443 | ); 444 | defaultConfigurationIsVisible = 0; 445 | }; 446 | /* End XCConfigurationList section */ 447 | }; 448 | rootObject = F761C5771B1A8F2000144FF0 /* Project object */; 449 | } 450 | -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/project.xcworkspace/xcuserdata/richardmcduffey.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcduffeyrt/RMSaveButton/ad676e52e99b5c61186e66073d364efc2427119f/RMSaveButton.xcodeproj/project.xcworkspace/xcuserdata/richardmcduffey.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/xcuserdata/richardmcduffey.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/xcuserdata/richardmcduffey.xcuserdatad/xcschemes/RMSaveButton.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /RMSaveButton.xcodeproj/xcuserdata/richardmcduffey.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RMSaveButton.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | F761C57E1B1A8F2000144FF0 16 | 17 | primary 18 | 19 | 20 | F761C5971B1A8F2000144FF0 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /RMSaveButton/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // RMSaveButton 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /RMSaveButton/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // RMSaveButton 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /RMSaveButton/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 | -------------------------------------------------------------------------------- /RMSaveButton/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 | -------------------------------------------------------------------------------- /RMSaveButton/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /RMSaveButton/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.McDuffAndRich.$(PRODUCT_NAME:rfc1034identifier) 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 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /RMSaveButton/RMSaveButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // RMSaveButton.h 3 | // 4 | // Created by Richard McDuffey on 5/20/15. 5 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | // SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | IB_DESIGNABLE @interface RMSaveButton : UIControl 30 | 31 | ///Label of the button. Default is SAVE. 32 | @property (nonatomic, copy) IBInspectable NSString *label; 33 | 34 | ///Color of the the button background. Default is rgb(43, 189, 224) 35 | @property (nonatomic, strong) IBInspectable UIColor *foregroundColor; 36 | 37 | ///Color of the button when highlighed. Default is rgb(108, 164, 176) 38 | @property (nonatomic, strong) IBInspectable UIColor *highlightedColor; 39 | 40 | ///Block that is called when the button is pressed. 41 | @property (nonatomic, copy) void (^startHandler) (void); 42 | 43 | ///Block that is called when the button is pressed before the download process is complete. 44 | @property (nonatomic, copy) void (^interruptHandler)(void); 45 | 46 | ///Optional block that can be called after the download process is completed. 47 | @property (nonatomic, copy) void (^completionHandler)(void); 48 | 49 | ///Performs out going animation. Must be called to end the process animation. 50 | - (void)endAnimation; 51 | 52 | ///Resets button to default state. 53 | - (void)resetButton; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /RMSaveButton/RMSaveButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // RMSaveButton.m 3 | // 4 | // Created by Richard McDuffey on 5/20/15. 5 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | // SOFTWARE. 24 | 25 | 26 | #import "RMSaveButton.h" 27 | 28 | NSString * const StartAnimationKey = @"Start"; 29 | const NSInteger NumberOfIndicatiors = 10; 30 | 31 | @interface RMSaveButton () 32 | 33 | @property (nonatomic, strong) CAReplicatorLayer *activityLayer; 34 | @property (nonatomic, strong) CAShapeLayer *backingLayer; 35 | @property (nonatomic, strong) CAShapeLayer *tickLayer; 36 | @property (nonatomic, strong) CALayer *marker; 37 | @property (nonatomic, strong) UILabel *titleLabel; 38 | @property (nonatomic, assign) CGRect collapsedFrame; 39 | @property (nonatomic, assign) CGRect expandedFrame; 40 | @property (nonatomic, assign) BOOL isAnimating; 41 | @property (nonatomic, assign) BOOL isInterrupted; 42 | 43 | @end 44 | 45 | @implementation RMSaveButton 46 | 47 | #pragma mark - Initialization 48 | 49 | - (instancetype)initWithCoder:(NSCoder *)aDecoder 50 | { 51 | self = [super initWithCoder:aDecoder]; 52 | 53 | if (self) { 54 | [self setup]; 55 | } 56 | 57 | return self; 58 | } 59 | 60 | - (instancetype)initWithFrame:(CGRect)frame 61 | { 62 | self = [super initWithFrame:frame]; 63 | if (self) { 64 | [self setup]; 65 | } 66 | 67 | return self; 68 | } 69 | 70 | - (instancetype)init 71 | { 72 | self = [super init]; 73 | if (self) { 74 | self.frame = CGRectMake(0, 0, 120, 40); 75 | [self setup]; 76 | } 77 | 78 | return self; 79 | } 80 | 81 | #pragma mark - Storyboard / NIB setup 82 | 83 | - (void)awakeFromNib 84 | { 85 | [super awakeFromNib]; 86 | 87 | [self setup]; 88 | } 89 | 90 | - (void)prepareForInterfaceBuilder 91 | { 92 | [self setup]; 93 | } 94 | 95 | #pragma mark - Setup and Layout 96 | 97 | - (void)setup 98 | { 99 | 100 | self.isAnimating = NO; 101 | 102 | self.backgroundColor = [UIColor clearColor]; 103 | 104 | self.backingLayer = [CAShapeLayer layer]; 105 | self.backingLayer.fillColor = self.foregroundColor.CGColor; 106 | [[self layer] addSublayer:self.backingLayer]; 107 | 108 | self.tickLayer = [CAShapeLayer layer]; 109 | self.tickLayer.strokeColor = [UIColor whiteColor].CGColor; 110 | self.tickLayer.lineWidth = 3; 111 | self.tickLayer.lineJoin = kCALineJoinRound; 112 | self.tickLayer.fillColor = [UIColor clearColor].CGColor; 113 | [[self layer] addSublayer:self.tickLayer]; 114 | 115 | self.activityLayer = [CAReplicatorLayer layer]; 116 | self.activityLayer.backgroundColor = [UIColor clearColor].CGColor; 117 | 118 | CGFloat angle = (2.0 * M_PI) / NumberOfIndicatiors; 119 | CATransform3D instanceRotation = CATransform3DMakeRotation(angle, 0.0, 0.0, 1.0); 120 | 121 | self.activityLayer.instanceTransform = instanceRotation; 122 | self.activityLayer.instanceCount = NumberOfIndicatiors; 123 | 124 | [[self layer] addSublayer:self.activityLayer]; 125 | 126 | self.marker = [CALayer layer]; 127 | [self.marker setBackgroundColor:[[UIColor darkGrayColor] CGColor]]; 128 | [self.activityLayer addSublayer:self.marker]; 129 | 130 | [self.marker setOpacity:0.0]; 131 | 132 | self.titleLabel = [UILabel new]; 133 | self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; 134 | self.titleLabel.textColor = [UIColor whiteColor]; 135 | self.titleLabel.backgroundColor = [UIColor clearColor]; 136 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 137 | self.titleLabel.numberOfLines = 1; 138 | self.titleLabel.minimumScaleFactor = 0.1; 139 | self.titleLabel.adjustsFontSizeToFitWidth = YES; 140 | [self addSubview:self.titleLabel]; 141 | 142 | 143 | 144 | [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[label]|" 145 | options:0 146 | metrics:nil 147 | views:@{@"label": _titleLabel}]]; 148 | 149 | [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[label]-|" 150 | options:0 151 | metrics:nil 152 | views:@{@"label": _titleLabel}]]; 153 | 154 | 155 | [self addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside]; 156 | [self registerNotifications]; 157 | 158 | } 159 | 160 | - (void)layoutSubviews 161 | { 162 | [super layoutSubviews]; 163 | 164 | CGFloat halfWidth = CGRectGetWidth(self.bounds) / 2; 165 | CGFloat halfHeight = CGRectGetHeight(self.bounds) / 2; 166 | 167 | self.expandedFrame = self.bounds; 168 | self.collapsedFrame = CGRectInset(self.bounds, halfWidth - halfHeight, 0); 169 | self.activityLayer.frame = CGRectInset(self.collapsedFrame, 5, 0); 170 | self.activityLayer.position = CGPointMake(halfWidth, halfHeight); 171 | self.marker.frame = CGRectMake(0, 0, self.collapsedFrame.size.width / 4, 4); 172 | self.marker.cornerRadius = 2; 173 | self.marker.position = CGPointMake(self.collapsedFrame.size.width / 4 - 4, self.collapsedFrame.size.height / 2); 174 | 175 | self.backingLayer.frame = self.bounds; 176 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:halfHeight]; 177 | self.backingLayer.path = path.CGPath; 178 | 179 | self.tickLayer.frame = self.bounds; 180 | 181 | UIFont *font = [UIFont systemFontOfSize:1.5]; 182 | float fontAspectFactor = 1.0 / font.lineHeight; 183 | self.titleLabel.font = [UIFont boldSystemFontOfSize:self.titleLabel.frame.size.height * fontAspectFactor]; 184 | self.titleLabel.text = self.label; 185 | } 186 | 187 | #pragma mark - Notifications 188 | 189 | - (void)registerNotifications { 190 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; 191 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; 192 | } 193 | 194 | - (void)applicationDidEnterBackground { 195 | if (self.isAnimating) { 196 | [self.marker removeAnimationForKey:StartAnimationKey]; 197 | } 198 | } 199 | 200 | - (void)applicationWillEnterForeground { 201 | if (self.isAnimating) { 202 | [self startActivityAnimation]; 203 | } 204 | } 205 | 206 | - (void)dealloc 207 | { 208 | [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:UIApplicationDidEnterBackgroundNotification]; 209 | [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:UIApplicationWillEnterForegroundNotification]; 210 | } 211 | 212 | #pragma mark - Setters and Getters 213 | 214 | - (NSString *)label 215 | { 216 | return _label != nil ? _label : @"SAVE"; 217 | } 218 | 219 | - (UIColor *)foregroundColor 220 | { 221 | return _foregroundColor != nil ? _foregroundColor : [UIColor colorWithRed:43/255.0 green:189/255.0 blue:224/255.0 alpha:1.0]; 222 | } 223 | 224 | - (UIColor *)highlightedColor 225 | { 226 | return _highlightedColor != nil ? _highlightedColor : [UIColor colorWithRed:108/255.0 green:164/255.0 blue:176/255.0 alpha:1.0]; 227 | } 228 | 229 | 230 | - (void)setHighlighted:(BOOL)highlighted 231 | { 232 | [super setHighlighted:highlighted]; 233 | 234 | if (highlighted && !self.isAnimating) { 235 | [CATransaction begin]; 236 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 237 | self.backingLayer.fillColor = self.highlightedColor.CGColor; 238 | [CATransaction commit]; 239 | } 240 | else { 241 | [CATransaction begin]; 242 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 243 | self.backingLayer.fillColor = self.foregroundColor.CGColor; 244 | [CATransaction commit]; 245 | } 246 | } 247 | #pragma mark - Helper Methods 248 | 249 | - (void)touchUpInside:(RMSaveButton *)sender 250 | { 251 | [self setSelected:!self.selected animated:YES]; 252 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 253 | } 254 | 255 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 256 | { 257 | if (animated && !self.isAnimating) { 258 | [self startAnimation]; 259 | 260 | if (self.startHandler != nil) { 261 | self.startHandler(); 262 | } 263 | } 264 | 265 | else if (self.isAnimating) { 266 | [self interruptAnimation]; 267 | 268 | if (self.interruptHandler != nil) { 269 | self.interruptHandler(); 270 | } 271 | } 272 | } 273 | 274 | - (void)drawTick 275 | { 276 | CGPoint origin = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); 277 | CGFloat radius = self.bounds.size.height / 2; 278 | 279 | origin.y = origin.y + radius / 3; 280 | 281 | UIBezierPath *path = [UIBezierPath bezierPath]; 282 | 283 | CGPoint start = CGPointZero; 284 | start.x = origin.x + (radius / 2) * cos(220 * M_PI / 180); 285 | start.y = origin.y + (radius / 2) * sin(220 * M_PI / 180); 286 | 287 | [path moveToPoint:start]; 288 | [path addLineToPoint:origin]; 289 | 290 | CGPoint end = CGPointZero; 291 | 292 | end.x = origin.x + radius * cos(300 * M_PI / 180); 293 | end.y = origin.y + radius * sin(300 * M_PI / 180); 294 | 295 | [path addLineToPoint:end]; 296 | 297 | self.tickLayer.path = path.CGPath; 298 | } 299 | 300 | - (void)resetButton 301 | { 302 | self.titleLabel.alpha = 1.0; 303 | self.tickLayer.path = nil; 304 | } 305 | 306 | #pragma mark - Animation 307 | 308 | - (void)startActivityAnimation 309 | { 310 | CABasicAnimation * fade = [CABasicAnimation animationWithKeyPath:@"opacity"]; 311 | [fade setFromValue:[NSNumber numberWithFloat:1.0]]; 312 | [fade setToValue:[NSNumber numberWithFloat:0.0]]; 313 | [fade setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]; 314 | [fade setRepeatCount:HUGE_VALF]; 315 | [fade setDuration:1.0]; 316 | CGFloat markerAnimationDuration = 1.0 / NumberOfIndicatiors; 317 | [self.activityLayer setInstanceDelay:markerAnimationDuration]; 318 | [self.marker addAnimation:fade forKey:StartAnimationKey]; 319 | } 320 | 321 | - (void)startAnimation 322 | { 323 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ 324 | 325 | self.titleLabel.alpha = 0.0; 326 | 327 | CGPathRef originalPath = self.backingLayer.path; 328 | 329 | UIBezierPath *end = [UIBezierPath bezierPathWithRoundedRect:self.collapsedFrame cornerRadius:self.frame.size.height / 2]; 330 | 331 | self.backingLayer.path = end.CGPath; 332 | 333 | CABasicAnimation *pathAnimate = [CABasicAnimation animationWithKeyPath:@"path"]; 334 | pathAnimate.duration = 0.6; 335 | pathAnimate.fromValue = (__bridge id)(originalPath); 336 | pathAnimate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 337 | pathAnimate.delegate = self; 338 | [self.backingLayer addAnimation:pathAnimate forKey:@"path"]; 339 | 340 | self.isAnimating = YES; 341 | 342 | }); 343 | } 344 | 345 | - (void)interruptAnimation 346 | { 347 | [self.marker removeAnimationForKey:StartAnimationKey]; 348 | 349 | CGPathRef originalPath = self.backingLayer.path; 350 | 351 | UIBezierPath *end = [UIBezierPath bezierPathWithRoundedRect:self.expandedFrame cornerRadius:self.frame.size.height / 2]; 352 | 353 | self.backingLayer.path = end.CGPath; 354 | 355 | CABasicAnimation *pathAnimate = [CABasicAnimation animationWithKeyPath:@"path"]; 356 | pathAnimate.duration = 0.6; 357 | pathAnimate.fromValue = (__bridge id)(originalPath); 358 | pathAnimate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 359 | pathAnimate.delegate = self; 360 | [self.backingLayer addAnimation:pathAnimate forKey:@"path"]; 361 | 362 | self.isAnimating = NO; 363 | self.isInterrupted = YES; 364 | } 365 | 366 | - (void)endAnimation 367 | { 368 | [self.marker removeAnimationForKey:StartAnimationKey]; 369 | 370 | CGPathRef originalPath = self.backingLayer.path; 371 | 372 | UIBezierPath *end = [UIBezierPath bezierPathWithRoundedRect:self.expandedFrame cornerRadius:self.frame.size.height / 2]; 373 | 374 | self.backingLayer.path = end.CGPath; 375 | 376 | CABasicAnimation *pathAnimate = [CABasicAnimation animationWithKeyPath:@"path"]; 377 | pathAnimate.duration = 0.6; 378 | pathAnimate.fromValue = (__bridge id)(originalPath); 379 | pathAnimate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 380 | pathAnimate.delegate = self; 381 | [self.backingLayer addAnimation:pathAnimate forKey:@"path"]; 382 | 383 | self.isAnimating = NO; 384 | } 385 | 386 | #pragma mark - CAAnimation Delegate 387 | 388 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 389 | { 390 | if (self.isAnimating) { 391 | [self startActivityAnimation]; 392 | } 393 | 394 | else if (!self.isAnimating && self.isInterrupted) { 395 | self.titleLabel.alpha = 1.0; 396 | } 397 | 398 | else { 399 | [self drawTick]; 400 | } 401 | } 402 | 403 | @end 404 | -------------------------------------------------------------------------------- /RMSaveButton/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // RMSaveButton 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /RMSaveButton/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // RMSaveButton 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "RMSaveButton.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet RMSaveButton *saveButton; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | NSURL *url = [NSURL URLWithString: 23 | @"http://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg"]; //@"http://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg 24 | 25 | NSURLSessionConfiguration *defaultConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; 26 | NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultConfig 27 | delegate:self 28 | delegateQueue:[NSOperationQueue mainQueue]]; 29 | 30 | NSURLSessionDownloadTask *task = [defaultSession downloadTaskWithURL:url]; 31 | 32 | self.saveButton.startHandler = ^void() { [task resume]; }; 33 | self.saveButton.interruptHandler = ^void() { [task cancel]; }; 34 | self.saveButton.completionHandler = ^void() { NSLog(@"Download completed."); }; 35 | 36 | } 37 | 38 | - (void)didReceiveMemoryWarning { 39 | [super didReceiveMemoryWarning]; 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite 44 | { 45 | double progress = (double) (totalBytesWritten/1024) / (double) (totalBytesExpectedToWrite/1024); 46 | NSLog(@"progress: %f", progress); 47 | } 48 | 49 | - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location 50 | { 51 | NSLog(@"Temporary File :%@\n", location); 52 | NSFileManager *fileManager = [NSFileManager defaultManager]; 53 | NSError *error; 54 | if (![fileManager removeItemAtURL:location error:&error]) { 55 | NSLog(@"Error: %@", [error localizedDescription]); 56 | } 57 | [self.saveButton endAnimation]; 58 | self.saveButton.completionHandler(); 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /RMSaveButton/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // RMSaveButton 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /RMSaveButtonTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.McDuffAndRich.$(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 | -------------------------------------------------------------------------------- /RMSaveButtonTests/RMSaveButtonTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // RMSaveButtonTests.m 3 | // RMSaveButtonTests 4 | // 5 | // Created by Richard McDuffey on 5/30/15. 6 | // Copyright (c) 2015 Richard McDuffey. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface RMSaveButtonTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation RMSaveButtonTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------