├── .DS_Store ├── .gitignore ├── Example ├── .DS_Store └── Snapping Slider Example │ ├── .DS_Store │ ├── Snapping Slider Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── Snapping Slider Example │ ├── .DS_Store │ ├── AppDelegate.swift │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift │ └── Snapping Slider ExampleTests │ ├── Info.plist │ └── Snapping_Slider_ExampleTests.swift ├── LICENSE ├── README.md ├── SnappingSlider.podspec └── SnappingSlider └── SnappingSlider.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rehatkathuria/SnappingSlider/50894f5b9dcd4f3302ee8ef92b687d78eb8ec9e5/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | Pods/ 20 | Carthage/Checkouts 21 | Carthage/Build 22 | -------------------------------------------------------------------------------- /Example/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rehatkathuria/SnappingSlider/50894f5b9dcd4f3302ee8ef92b687d78eb8ec9e5/Example/.DS_Store -------------------------------------------------------------------------------- /Example/Snapping Slider Example/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rehatkathuria/SnappingSlider/50894f5b9dcd4f3302ee8ef92b687d78eb8ec9e5/Example/Snapping Slider Example/.DS_Store -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F5A9AE5D1AE6D6D600E4DB27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A9AE5C1AE6D6D600E4DB27 /* AppDelegate.swift */; }; 11 | F5A9AE5F1AE6D6D600E4DB27 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A9AE5E1AE6D6D600E4DB27 /* ViewController.swift */; }; 12 | F5A9AE641AE6D6D600E4DB27 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F5A9AE631AE6D6D600E4DB27 /* Images.xcassets */; }; 13 | F5A9AE731AE6D6D700E4DB27 /* Snapping_Slider_ExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A9AE721AE6D6D700E4DB27 /* Snapping_Slider_ExampleTests.swift */; }; 14 | F5A9AE7D1AE6D73500E4DB27 /* SnappingSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A9AE7C1AE6D73500E4DB27 /* SnappingSlider.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXContainerItemProxy section */ 18 | F5A9AE6D1AE6D6D700E4DB27 /* PBXContainerItemProxy */ = { 19 | isa = PBXContainerItemProxy; 20 | containerPortal = F5A9AE4F1AE6D6D600E4DB27 /* Project object */; 21 | proxyType = 1; 22 | remoteGlobalIDString = F5A9AE561AE6D6D600E4DB27; 23 | remoteInfo = "Snapping Slider Example"; 24 | }; 25 | /* End PBXContainerItemProxy section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | F5A9AE571AE6D6D600E4DB27 /* Snapping Slider Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Snapping Slider Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | F5A9AE5B1AE6D6D600E4DB27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | F5A9AE5C1AE6D6D600E4DB27 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | F5A9AE5E1AE6D6D600E4DB27 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 32 | F5A9AE631AE6D6D600E4DB27 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 33 | F5A9AE6C1AE6D6D700E4DB27 /* Snapping Slider ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Snapping Slider ExampleTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | F5A9AE711AE6D6D700E4DB27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | F5A9AE721AE6D6D700E4DB27 /* Snapping_Slider_ExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Snapping_Slider_ExampleTests.swift; sourceTree = ""; }; 36 | F5A9AE7C1AE6D73500E4DB27 /* SnappingSlider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnappingSlider.swift; path = ../../../SnappingSlider/SnappingSlider.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | F5A9AE541AE6D6D600E4DB27 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | F5A9AE691AE6D6D700E4DB27 /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | F5A9AE4E1AE6D6D600E4DB27 = { 58 | isa = PBXGroup; 59 | children = ( 60 | F5A9AE591AE6D6D600E4DB27 /* Snapping Slider Example */, 61 | F5A9AE6F1AE6D6D700E4DB27 /* Snapping Slider ExampleTests */, 62 | F5A9AE581AE6D6D600E4DB27 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | F5A9AE581AE6D6D600E4DB27 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | F5A9AE571AE6D6D600E4DB27 /* Snapping Slider Example.app */, 70 | F5A9AE6C1AE6D6D700E4DB27 /* Snapping Slider ExampleTests.xctest */, 71 | ); 72 | name = Products; 73 | sourceTree = ""; 74 | }; 75 | F5A9AE591AE6D6D600E4DB27 /* Snapping Slider Example */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | F5A9AE5C1AE6D6D600E4DB27 /* AppDelegate.swift */, 79 | F5A9AE5E1AE6D6D600E4DB27 /* ViewController.swift */, 80 | F5A9AE631AE6D6D600E4DB27 /* Images.xcassets */, 81 | F5A9AE5A1AE6D6D600E4DB27 /* Supporting Files */, 82 | ); 83 | path = "Snapping Slider Example"; 84 | sourceTree = ""; 85 | }; 86 | F5A9AE5A1AE6D6D600E4DB27 /* Supporting Files */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | F5A9AE7C1AE6D73500E4DB27 /* SnappingSlider.swift */, 90 | F5A9AE5B1AE6D6D600E4DB27 /* Info.plist */, 91 | ); 92 | name = "Supporting Files"; 93 | sourceTree = ""; 94 | }; 95 | F5A9AE6F1AE6D6D700E4DB27 /* Snapping Slider ExampleTests */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | F5A9AE721AE6D6D700E4DB27 /* Snapping_Slider_ExampleTests.swift */, 99 | F5A9AE701AE6D6D700E4DB27 /* Supporting Files */, 100 | ); 101 | path = "Snapping Slider ExampleTests"; 102 | sourceTree = ""; 103 | }; 104 | F5A9AE701AE6D6D700E4DB27 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | F5A9AE711AE6D6D700E4DB27 /* Info.plist */, 108 | ); 109 | name = "Supporting Files"; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | F5A9AE561AE6D6D600E4DB27 /* Snapping Slider Example */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = F5A9AE761AE6D6D700E4DB27 /* Build configuration list for PBXNativeTarget "Snapping Slider Example" */; 118 | buildPhases = ( 119 | F5A9AE531AE6D6D600E4DB27 /* Sources */, 120 | F5A9AE541AE6D6D600E4DB27 /* Frameworks */, 121 | F5A9AE551AE6D6D600E4DB27 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = "Snapping Slider Example"; 128 | productName = "Snapping Slider Example"; 129 | productReference = F5A9AE571AE6D6D600E4DB27 /* Snapping Slider Example.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | F5A9AE6B1AE6D6D700E4DB27 /* Snapping Slider ExampleTests */ = { 133 | isa = PBXNativeTarget; 134 | buildConfigurationList = F5A9AE791AE6D6D700E4DB27 /* Build configuration list for PBXNativeTarget "Snapping Slider ExampleTests" */; 135 | buildPhases = ( 136 | F5A9AE681AE6D6D700E4DB27 /* Sources */, 137 | F5A9AE691AE6D6D700E4DB27 /* Frameworks */, 138 | F5A9AE6A1AE6D6D700E4DB27 /* Resources */, 139 | ); 140 | buildRules = ( 141 | ); 142 | dependencies = ( 143 | F5A9AE6E1AE6D6D700E4DB27 /* PBXTargetDependency */, 144 | ); 145 | name = "Snapping Slider ExampleTests"; 146 | productName = "Snapping Slider ExampleTests"; 147 | productReference = F5A9AE6C1AE6D6D700E4DB27 /* Snapping Slider ExampleTests.xctest */; 148 | productType = "com.apple.product-type.bundle.unit-test"; 149 | }; 150 | /* End PBXNativeTarget section */ 151 | 152 | /* Begin PBXProject section */ 153 | F5A9AE4F1AE6D6D600E4DB27 /* Project object */ = { 154 | isa = PBXProject; 155 | attributes = { 156 | LastSwiftUpdateCheck = 0720; 157 | LastUpgradeCheck = 0800; 158 | ORGANIZATIONNAME = "Kathuria Ltd"; 159 | TargetAttributes = { 160 | F5A9AE561AE6D6D600E4DB27 = { 161 | CreatedOnToolsVersion = 6.3; 162 | LastSwiftMigration = 0800; 163 | }; 164 | F5A9AE6B1AE6D6D700E4DB27 = { 165 | CreatedOnToolsVersion = 6.3; 166 | LastSwiftMigration = 0800; 167 | TestTargetID = F5A9AE561AE6D6D600E4DB27; 168 | }; 169 | }; 170 | }; 171 | buildConfigurationList = F5A9AE521AE6D6D600E4DB27 /* Build configuration list for PBXProject "Snapping Slider Example" */; 172 | compatibilityVersion = "Xcode 3.2"; 173 | developmentRegion = English; 174 | hasScannedForEncodings = 0; 175 | knownRegions = ( 176 | en, 177 | Base, 178 | ); 179 | mainGroup = F5A9AE4E1AE6D6D600E4DB27; 180 | productRefGroup = F5A9AE581AE6D6D600E4DB27 /* Products */; 181 | projectDirPath = ""; 182 | projectRoot = ""; 183 | targets = ( 184 | F5A9AE561AE6D6D600E4DB27 /* Snapping Slider Example */, 185 | F5A9AE6B1AE6D6D700E4DB27 /* Snapping Slider ExampleTests */, 186 | ); 187 | }; 188 | /* End PBXProject section */ 189 | 190 | /* Begin PBXResourcesBuildPhase section */ 191 | F5A9AE551AE6D6D600E4DB27 /* Resources */ = { 192 | isa = PBXResourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | F5A9AE641AE6D6D600E4DB27 /* Images.xcassets in Resources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | F5A9AE6A1AE6D6D700E4DB27 /* Resources */ = { 200 | isa = PBXResourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | }; 206 | /* End PBXResourcesBuildPhase section */ 207 | 208 | /* Begin PBXSourcesBuildPhase section */ 209 | F5A9AE531AE6D6D600E4DB27 /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | F5A9AE5F1AE6D6D600E4DB27 /* ViewController.swift in Sources */, 214 | F5A9AE7D1AE6D73500E4DB27 /* SnappingSlider.swift in Sources */, 215 | F5A9AE5D1AE6D6D600E4DB27 /* AppDelegate.swift in Sources */, 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | }; 219 | F5A9AE681AE6D6D700E4DB27 /* Sources */ = { 220 | isa = PBXSourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | F5A9AE731AE6D6D700E4DB27 /* Snapping_Slider_ExampleTests.swift in Sources */, 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | /* End PBXSourcesBuildPhase section */ 228 | 229 | /* Begin PBXTargetDependency section */ 230 | F5A9AE6E1AE6D6D700E4DB27 /* PBXTargetDependency */ = { 231 | isa = PBXTargetDependency; 232 | target = F5A9AE561AE6D6D600E4DB27 /* Snapping Slider Example */; 233 | targetProxy = F5A9AE6D1AE6D6D700E4DB27 /* PBXContainerItemProxy */; 234 | }; 235 | /* End PBXTargetDependency section */ 236 | 237 | /* Begin XCBuildConfiguration section */ 238 | F5A9AE741AE6D6D700E4DB27 /* Debug */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 243 | CLANG_CXX_LIBRARY = "libc++"; 244 | CLANG_ENABLE_MODULES = YES; 245 | CLANG_ENABLE_OBJC_ARC = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INFINITE_RECURSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 258 | COPY_PHASE_STRIP = NO; 259 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | ENABLE_TESTABILITY = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu99; 263 | GCC_DYNAMIC_NO_PIC = NO; 264 | GCC_NO_COMMON_BLOCKS = YES; 265 | GCC_OPTIMIZATION_LEVEL = 0; 266 | GCC_PREPROCESSOR_DEFINITIONS = ( 267 | "DEBUG=1", 268 | "$(inherited)", 269 | ); 270 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 273 | GCC_WARN_UNDECLARED_SELECTOR = YES; 274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 275 | GCC_WARN_UNUSED_FUNCTION = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 278 | MTL_ENABLE_DEBUG_INFO = YES; 279 | ONLY_ACTIVE_ARCH = YES; 280 | SDKROOT = iphoneos; 281 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 282 | TARGETED_DEVICE_FAMILY = "1,2"; 283 | }; 284 | name = Debug; 285 | }; 286 | F5A9AE751AE6D6D700E4DB27 /* Release */ = { 287 | isa = XCBuildConfiguration; 288 | buildSettings = { 289 | ALWAYS_SEARCH_USER_PATHS = NO; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INFINITE_RECURSION = YES; 300 | CLANG_WARN_INT_CONVERSION = YES; 301 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 302 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 303 | CLANG_WARN_UNREACHABLE_CODE = YES; 304 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 305 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 306 | COPY_PHASE_STRIP = NO; 307 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 308 | ENABLE_NS_ASSERTIONS = NO; 309 | ENABLE_STRICT_OBJC_MSGSEND = YES; 310 | GCC_C_LANGUAGE_STANDARD = gnu99; 311 | GCC_NO_COMMON_BLOCKS = YES; 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 319 | MTL_ENABLE_DEBUG_INFO = NO; 320 | SDKROOT = iphoneos; 321 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 322 | TARGETED_DEVICE_FAMILY = "1,2"; 323 | VALIDATE_PRODUCT = YES; 324 | }; 325 | name = Release; 326 | }; 327 | F5A9AE771AE6D6D700E4DB27 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 332 | CODE_SIGN_IDENTITY = "iPhone Developer"; 333 | INFOPLIST_FILE = "Snapping Slider Example/Info.plist"; 334 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 336 | PRODUCT_BUNDLE_IDENTIFIER = "com.kathuria.$(PRODUCT_NAME:rfc1034identifier)"; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | SWIFT_VERSION = 3.0; 339 | TARGETED_DEVICE_FAMILY = 1; 340 | }; 341 | name = Debug; 342 | }; 343 | F5A9AE781AE6D6D700E4DB27 /* Release */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 347 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 348 | CODE_SIGN_IDENTITY = "iPhone Developer"; 349 | INFOPLIST_FILE = "Snapping Slider Example/Info.plist"; 350 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 351 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 352 | PRODUCT_BUNDLE_IDENTIFIER = "com.kathuria.$(PRODUCT_NAME:rfc1034identifier)"; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | SWIFT_VERSION = 3.0; 355 | TARGETED_DEVICE_FAMILY = 1; 356 | }; 357 | name = Release; 358 | }; 359 | F5A9AE7A1AE6D6D700E4DB27 /* Debug */ = { 360 | isa = XCBuildConfiguration; 361 | buildSettings = { 362 | BUNDLE_LOADER = "$(TEST_HOST)"; 363 | FRAMEWORK_SEARCH_PATHS = ( 364 | "$(SDKROOT)/Developer/Library/Frameworks", 365 | "$(inherited)", 366 | ); 367 | GCC_PREPROCESSOR_DEFINITIONS = ( 368 | "DEBUG=1", 369 | "$(inherited)", 370 | ); 371 | INFOPLIST_FILE = "Snapping Slider ExampleTests/Info.plist"; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = "com.kathuria.$(PRODUCT_NAME:rfc1034identifier)"; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_VERSION = 3.0; 376 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Snapping Slider Example.app/Snapping Slider Example"; 377 | }; 378 | name = Debug; 379 | }; 380 | F5A9AE7B1AE6D6D700E4DB27 /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | BUNDLE_LOADER = "$(TEST_HOST)"; 384 | FRAMEWORK_SEARCH_PATHS = ( 385 | "$(SDKROOT)/Developer/Library/Frameworks", 386 | "$(inherited)", 387 | ); 388 | INFOPLIST_FILE = "Snapping Slider ExampleTests/Info.plist"; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 390 | PRODUCT_BUNDLE_IDENTIFIER = "com.kathuria.$(PRODUCT_NAME:rfc1034identifier)"; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | SWIFT_VERSION = 3.0; 393 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Snapping Slider Example.app/Snapping Slider Example"; 394 | }; 395 | name = Release; 396 | }; 397 | /* End XCBuildConfiguration section */ 398 | 399 | /* Begin XCConfigurationList section */ 400 | F5A9AE521AE6D6D600E4DB27 /* Build configuration list for PBXProject "Snapping Slider Example" */ = { 401 | isa = XCConfigurationList; 402 | buildConfigurations = ( 403 | F5A9AE741AE6D6D700E4DB27 /* Debug */, 404 | F5A9AE751AE6D6D700E4DB27 /* Release */, 405 | ); 406 | defaultConfigurationIsVisible = 0; 407 | defaultConfigurationName = Release; 408 | }; 409 | F5A9AE761AE6D6D700E4DB27 /* Build configuration list for PBXNativeTarget "Snapping Slider Example" */ = { 410 | isa = XCConfigurationList; 411 | buildConfigurations = ( 412 | F5A9AE771AE6D6D700E4DB27 /* Debug */, 413 | F5A9AE781AE6D6D700E4DB27 /* Release */, 414 | ); 415 | defaultConfigurationIsVisible = 0; 416 | defaultConfigurationName = Release; 417 | }; 418 | F5A9AE791AE6D6D700E4DB27 /* Build configuration list for PBXNativeTarget "Snapping Slider ExampleTests" */ = { 419 | isa = XCConfigurationList; 420 | buildConfigurations = ( 421 | F5A9AE7A1AE6D6D700E4DB27 /* Debug */, 422 | F5A9AE7B1AE6D6D700E4DB27 /* Release */, 423 | ); 424 | defaultConfigurationIsVisible = 0; 425 | defaultConfigurationName = Release; 426 | }; 427 | /* End XCConfigurationList section */ 428 | }; 429 | rootObject = F5A9AE4F1AE6D6D600E4DB27 /* Project object */; 430 | } 431 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rehatkathuria/SnappingSlider/50894f5b9dcd4f3302ee8ef92b687d78eb8ec9e5/Example/Snapping Slider Example/Snapping Slider Example/.DS_Store -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Snapping Slider Example 4 | // 5 | // Created by Rehat Kathuria on 21/04/2015. 6 | // Copyright (c) 2015 Kathuria Ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | 19 | // Override point for customization after application launch. 20 | window = UIWindow(frame: UIScreen.main.bounds) 21 | if let mainWindow = window { 22 | 23 | mainWindow.backgroundColor = UIColor.white 24 | mainWindow.rootViewController = ViewController() 25 | mainWindow.makeKeyAndVisible() 26 | } 27 | return true 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/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 | } -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "minimum-system-version" : "7.0", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "orientation" : "portrait", 11 | "idiom" : "iphone", 12 | "minimum-system-version" : "7.0", 13 | "subtype" : "retina4", 14 | "scale" : "2x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Snapping Slider Example 4 | // 5 | // Created by Rehat Kathuria on 21/04/2015. 6 | // Copyright (c) 2015 Kathuria Ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class ViewController: UIViewController, SnappingSliderDelegate { 12 | 13 | fileprivate var numberOfCupsOfTeaIHaveDrankSoFar:Int = 0 14 | fileprivate let bladderFillLabel:UILabel = UILabel(frame: CGRect.zero) 15 | fileprivate let snappingSlider:SnappingSlider = SnappingSlider(frame: CGRect(x: 0.0, y: 0.0, width: 10.0, height: 10.0), title: "Slide Me") 16 | 17 | override func viewDidLoad() { 18 | 19 | super.viewDidLoad() 20 | 21 | bladderFillLabel.frame = CGRect(x: 0.0, y: 0.0, width: self.view.bounds.size.width * 0.5, height: 80.0) 22 | bladderFillLabel.center = CGPoint(x: self.view.bounds.size.width * 0.5, y: self.view.bounds.size.height * 0.5 - bladderFillLabel.bounds.size.height * 0.75) 23 | bladderFillLabel.font = UIFont(name: "TrebuchetMS-Bold", size: 25.0) 24 | bladderFillLabel.textColor = UIColor.lightGray 25 | bladderFillLabel.textAlignment = NSTextAlignment.center 26 | bladderFillLabel.text = "\(numberOfCupsOfTeaIHaveDrankSoFar)" 27 | self.view.addSubview(bladderFillLabel) 28 | 29 | snappingSlider.delegate = self 30 | snappingSlider.frame = CGRect(x: 0.0, y: 0.0, width: self.view.bounds.size.width * 0.5, height: 50.0) 31 | snappingSlider.center = CGPoint(x: self.view.bounds.size.width * 0.5, y: self.view.bounds.size.height * 0.5) 32 | self.view.addSubview(snappingSlider) 33 | } 34 | 35 | func snappingSliderDidIncrementValue(_ snapSwitch: SnappingSlider) { 36 | 37 | numberOfCupsOfTeaIHaveDrankSoFar += 1 38 | bladderFillLabel.text = "\(numberOfCupsOfTeaIHaveDrankSoFar)" 39 | } 40 | 41 | func snappingSliderDidDecrementValue(_ snapSwitch: SnappingSlider) { 42 | 43 | numberOfCupsOfTeaIHaveDrankSoFar = max(0, numberOfCupsOfTeaIHaveDrankSoFar - 1) 44 | bladderFillLabel.text = "\(numberOfCupsOfTeaIHaveDrankSoFar)" 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider ExampleTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/Snapping Slider Example/Snapping Slider ExampleTests/Snapping_Slider_ExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Snapping_Slider_ExampleTests.swift 3 | // Snapping Slider ExampleTests 4 | // 5 | // Created by Rehat Kathuria on 21/04/2015. 6 | // Copyright (c) 2015 Kathuria Ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class Snapping_Slider_ExampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Rehat Kathuria 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SnappingSlider 2 | 3 | A beautiful slider control for iOS. 4 | 5 |

6 | Look at that beauty! 7 |

8 | 9 | ## Installation 10 | There are two ways to add the control to your project; you can add it as a submodule if you're using GIT as a versioning system or you can install it through CocoaPods. Examples of both are outlined below. 11 | 12 | `git submodule add https://github.com/rehatkathuria/SnappingSlider` 13 | 14 | `pod "SnappingSlider"` 15 | 16 | ## Usage 17 | It's simple, really. In essence, all you need to do is instantiate a slider with a title and conform to the delegate offered. 18 | 19 | ```swift 20 | let slider = SnappingSlider(frame: CGRectMake(0.0, 0.0, 10.0, 10.0), title: "Slide Me") 21 | slider.delegate = self 22 | 23 | myAwesomeViewController.view.addSubView = slider 24 | 25 | 26 | ... 27 | 28 | 29 | func snappingSliderDidIncrementValue(snapSwitch: SnappingSlider) { 30 | 31 | } 32 | 33 | func snappingSliderDidDecrementValue(snapSwitch: SnappingSlider) { 34 | 35 | } 36 | ``` 37 | 38 | ## Author 39 | This control has been open-sourced by [Rehat Kathuria](http://kthr.co). You can follow him on twitter, [here](http://twitter.com/rhtkth), and hire him for freelance projects, [here](mailto:rehat@kathuria.co). 40 | 41 | ## License & Other Boring Stuff 42 | Licensed under MIT. If you use the control somewhere, [do let me know](http://twitter.com/rehatkat). I'd love to see it out in the wild. 43 | -------------------------------------------------------------------------------- /SnappingSlider.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SnappingSlider" 3 | s.version = "1.0" 4 | s.summary = "A beautiful slider control for iOS built purely upon Swift." 5 | s.description = <<-DESC 6 | A slider control built upon UIKitDynamic using Swift. Simple and effecient. 7 | DESC 8 | s.homepage = "https://github.com/rehatkathuria/SnappingSlider" 9 | s.screenshots = "http://i.imgur.com/D6IsT2r.gif" 10 | s.license = { :type => "MIT", :file => "LICENSE" } 11 | s.author = { "Rehat Kathuria" => "rehat@kathuria.co" } 12 | s.social_media_url = "http://twitter.com/rhtkth" 13 | s.platform = :ios, "8.0" 14 | s.source = { :git => "https://github.com/rehatkathuria/SnappingSlider.git", :tag => "v#{s.version}" } 15 | s.source_files = "SnappingSlider/SnappingSlider.swift" 16 | s.requires_arc = true 17 | end 18 | -------------------------------------------------------------------------------- /SnappingSlider/SnappingSlider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Rehat Kathuria 3 | // www.kthr.co 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // 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, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | import UIKit 23 | 24 | public protocol SnappingSliderDelegate: class { 25 | 26 | func snappingSliderDidIncrementValue(_ slider:SnappingSlider) 27 | func snappingSliderDidDecrementValue(_ slider:SnappingSlider) 28 | } 29 | 30 | open class SnappingSlider: UIView { 31 | 32 | final public weak var delegate:SnappingSliderDelegate? 33 | final public var shouldContinueAlteringValueUntilGestureCancels:Bool = false 34 | final public var incrementAndDecrementLabelFont:UIFont = UIFont(name: "TrebuchetMS-Bold", size: 18.0)! { didSet { setNeedsLayout() } } 35 | final public var incrementAndDecrementLabelTextColor:UIColor = UIColor.white { didSet { setNeedsLayout() } } 36 | final public var incrementAndDecrementBackgroundColor:UIColor = UIColor(red:0.36, green:0.65, blue:0.65, alpha:1) { didSet { setNeedsLayout() } } 37 | final public var sliderColor:UIColor = UIColor(red:0.42, green:0.76, blue:0.74, alpha:1) { didSet { setNeedsLayout() } } 38 | final public var sliderTitleFont:UIFont = UIFont(name: "TrebuchetMS-Bold", size: 15.0)! { didSet { setNeedsLayout() } } 39 | final public var sliderTitleColor:UIColor = UIColor.white { didSet { setNeedsLayout() } } 40 | final public var sliderTitleText:String = "Slide Me" { didSet { setNeedsLayout() } } 41 | final public var sliderCornerRadius:CGFloat = 3.0 { didSet { setNeedsLayout() } } 42 | 43 | final fileprivate let sliderContainer = UIView(frame: CGRect.zero) 44 | final fileprivate let minusLabel = UILabel(frame: CGRect.zero) 45 | final fileprivate let plusLabel = UILabel(frame: CGRect.zero) 46 | final fileprivate let sliderView = UIView(frame: CGRect.zero) 47 | final fileprivate let sliderViewLabel = UILabel(frame: CGRect.zero) 48 | 49 | final fileprivate var isCurrentDraggingSlider = false 50 | final fileprivate var lastDelegateFireOffset = CGFloat(0) 51 | final fileprivate var touchesBeganPoint = CGPoint.zero 52 | final fileprivate var valueChangingTimer:Timer? 53 | 54 | final fileprivate let sliderPanGestureRecogniser = UIPanGestureRecognizer() 55 | final fileprivate let dynamicButtonAnimator = UIDynamicAnimator() 56 | final fileprivate var snappingBehavior:SliderSnappingBehavior? 57 | 58 | public init(frame:CGRect, title:String) { 59 | 60 | super.init(frame: frame) 61 | 62 | sliderTitleText = title 63 | setup() 64 | setNeedsLayout() 65 | } 66 | 67 | required public init?(coder aDecoder: NSCoder) { 68 | 69 | super.init(coder: aDecoder) 70 | setup() 71 | setNeedsLayout() 72 | } 73 | 74 | fileprivate func setup() { 75 | 76 | sliderContainer.backgroundColor = backgroundColor 77 | 78 | minusLabel.text = "-" 79 | minusLabel.textAlignment = NSTextAlignment.center 80 | sliderContainer.addSubview(minusLabel) 81 | 82 | plusLabel.text = "+" 83 | plusLabel.textAlignment = NSTextAlignment.center 84 | sliderContainer.addSubview(plusLabel) 85 | 86 | sliderContainer.addSubview(sliderView) 87 | 88 | sliderViewLabel.isUserInteractionEnabled = false 89 | sliderViewLabel.textAlignment = NSTextAlignment.center 90 | sliderViewLabel.textColor = sliderTitleColor 91 | sliderView.addSubview(sliderViewLabel) 92 | 93 | sliderPanGestureRecogniser.addTarget(self, action: #selector(type(of: self).handleGesture(_:))) 94 | sliderView.addGestureRecognizer(sliderPanGestureRecogniser) 95 | 96 | sliderContainer.center = CGPoint(x: bounds.size.width * 0.5, y: bounds.size.height * 0.5) 97 | addSubview(sliderContainer) 98 | clipsToBounds = true 99 | } 100 | 101 | override open func layoutSubviews() { 102 | 103 | super.layoutSubviews() 104 | 105 | if snappingBehavior?.snappingPoint.x != center.x { 106 | 107 | snappingBehavior = SliderSnappingBehavior(item: sliderView, snapToPoint: CGPoint(x: bounds.size.width * 0.5, y: bounds.size.height * 0.5)) 108 | lastDelegateFireOffset = sliderView.center.x 109 | } 110 | 111 | sliderContainer.frame = frame 112 | sliderContainer.center = CGPoint(x: bounds.size.width * 0.5, y: bounds.size.height * 0.5) 113 | sliderContainer.backgroundColor = incrementAndDecrementBackgroundColor 114 | 115 | minusLabel.frame = CGRect(x: 0.0, y: 0.0, width: bounds.size.width * 0.25, height: bounds.size.height) 116 | minusLabel.center = CGPoint(x: minusLabel.bounds.size.width * 0.5, y: bounds.size.height * 0.5) 117 | minusLabel.backgroundColor = incrementAndDecrementBackgroundColor 118 | minusLabel.font = incrementAndDecrementLabelFont 119 | minusLabel.textColor = incrementAndDecrementLabelTextColor 120 | 121 | plusLabel.frame = CGRect(x: 0.0, y: 0.0, width: bounds.size.width * 0.25, height: bounds.size.height) 122 | plusLabel.center = CGPoint(x: bounds.size.width - plusLabel.bounds.size.width * 0.5, y: bounds.size.height * 0.5) 123 | plusLabel.backgroundColor = incrementAndDecrementBackgroundColor 124 | plusLabel.font = incrementAndDecrementLabelFont 125 | plusLabel.textColor = incrementAndDecrementLabelTextColor 126 | 127 | sliderView.frame = CGRect(x: 0.0, y: 0.0, width: bounds.size.width * 0.5, height: bounds.size.height) 128 | sliderView.center = CGPoint(x: bounds.size.width * 0.5, y: bounds.size.height * 0.5) 129 | sliderView.backgroundColor = sliderColor 130 | 131 | sliderViewLabel.frame = CGRect(x: 0.0, y: 0.0, width: sliderView.bounds.size.width, height: sliderView.bounds.size.height) 132 | sliderViewLabel.center = CGPoint(x: sliderViewLabel.bounds.size.width * 0.5, y: sliderViewLabel.bounds.size.height * 0.5) 133 | sliderViewLabel.backgroundColor = sliderColor 134 | sliderViewLabel.font = sliderTitleFont 135 | sliderViewLabel.text = sliderTitleText 136 | 137 | layer.cornerRadius = sliderCornerRadius 138 | } 139 | 140 | // MARK: Gesture & Timer Handling 141 | 142 | final func handleGesture(_ sender: UIGestureRecognizer) { 143 | 144 | guard let snapBehavior = snappingBehavior else { return } 145 | 146 | if sender as NSObject == sliderPanGestureRecogniser { 147 | 148 | switch sender.state { 149 | 150 | case .began: 151 | 152 | isCurrentDraggingSlider = true 153 | touchesBeganPoint = sliderPanGestureRecogniser.translation(in: sliderView) 154 | dynamicButtonAnimator.removeBehavior(snapBehavior) 155 | lastDelegateFireOffset = (bounds.size.width * 0.5) + ((touchesBeganPoint.x + touchesBeganPoint.x) * 0.40) 156 | 157 | case .changed: 158 | 159 | valueChangingTimer?.invalidate() 160 | 161 | let translationInView = sliderPanGestureRecogniser.translation(in: sliderView) 162 | let translatedCenterX:CGFloat = (bounds.size.width * 0.5) + ((touchesBeganPoint.x + translationInView.x) * 0.40) 163 | sliderView.center = CGPoint(x: translatedCenterX, y: sliderView.center.y); 164 | 165 | if (translatedCenterX < lastDelegateFireOffset) { 166 | 167 | if (fabs(lastDelegateFireOffset - translatedCenterX) >= (sliderView.bounds.size.width * 0.15)) { 168 | 169 | delegate?.snappingSliderDidDecrementValue(self) 170 | lastDelegateFireOffset = translatedCenterX 171 | } 172 | } 173 | else { 174 | 175 | if (fabs(lastDelegateFireOffset - translatedCenterX) >= (sliderView.bounds.size.width * 0.15)) { 176 | 177 | delegate?.snappingSliderDidIncrementValue(self) 178 | lastDelegateFireOffset = translatedCenterX 179 | } 180 | } 181 | 182 | if shouldContinueAlteringValueUntilGestureCancels { 183 | 184 | valueChangingTimer = Timer.scheduledTimer(timeInterval: 0.7, target: self, selector: NSSelectorFromString("handleTimer:"), userInfo: nil, repeats: true) 185 | } 186 | 187 | case .ended: 188 | 189 | fallthrough 190 | 191 | case .failed: 192 | 193 | fallthrough 194 | 195 | case .cancelled: 196 | 197 | dynamicButtonAnimator.addBehavior(snapBehavior) 198 | isCurrentDraggingSlider = false 199 | lastDelegateFireOffset = center.x 200 | valueChangingTimer?.invalidate() 201 | 202 | case .possible: 203 | 204 | // Swift requires at least one statement per case 205 | _ = 0 206 | } 207 | } 208 | } 209 | 210 | final func handleTimer(_ sender: Timer) { 211 | 212 | if sliderView.frame.midX > self.bounds.midX { 213 | 214 | delegate?.snappingSliderDidIncrementValue(self) 215 | } 216 | else { 217 | 218 | delegate?.snappingSliderDidDecrementValue(self) 219 | } 220 | } 221 | 222 | } 223 | 224 | final class SliderSnappingBehavior: UIDynamicBehavior { 225 | 226 | let snappingPoint:CGPoint 227 | 228 | init(item: UIDynamicItem, snapToPoint point: CGPoint) { 229 | 230 | let dynamicItemBehavior:UIDynamicItemBehavior = UIDynamicItemBehavior(items: [item]) 231 | dynamicItemBehavior.allowsRotation = false 232 | 233 | let snapBehavior:UISnapBehavior = UISnapBehavior(item: item, snapTo: point) 234 | snapBehavior.damping = 0.25 235 | 236 | snappingPoint = point 237 | 238 | super.init() 239 | 240 | addChildBehavior(dynamicItemBehavior) 241 | addChildBehavior(snapBehavior) 242 | } 243 | 244 | } 245 | --------------------------------------------------------------------------------