├── .gitignore ├── LICENSE ├── README.md ├── STNumberLabel.gif ├── STNumberLabel.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── StormXX.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── StormXX.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist └── STNumberLabel ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── CharacterExtension.swift ├── Info.plist ├── STNumberLabel.swift ├── STScrollNumberView.swift ├── STScrollNumberViewExtension.swift ├── UIViewExtension.swift └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ 3 | *.pbxuser 4 | !default.pbxuser 5 | *.mode1v3 6 | !default.mode1v3 7 | *.mode2v3 8 | !default.mode2v3 9 | *.perspectivev3 10 | !default.perspectivev3 11 | !default.xcworkspace 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | xcshareddata 18 | MoneyNetwork.xcodeproj/xcuserdata 19 | #Breakpoints_v2.xcbkptlist 20 | xcschememanagement.plist 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 冬菇桑。 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 | # STNumberLabel 2 | A scroll number label 3 | 4 | ## GIF 5 | ![image](https://raw.githubusercontent.com/StormXX/STNumberLabel/master/STNumberLabel.gif) 6 | 7 | ## Usage 8 | 1. init the label with frame and font `STNumberLabel(frame: CGRect(x: 150, y: 200, width: 200, height: 50), digit: 4, font: UIFont.systemFont(ofSize: 22.0), singleNumberSize: CGSize(width: 20, height: 50))` 9 | 2. call `numberlabel.scrollToNumber(number)` when you want the label to scroll number 10 | 11 | ## Minimum Requirement 12 | - iOS 8.0 13 | 14 | ## License 15 | - STNumberLabel is released under the MIT license. See [LICENSE](https://github.com/StormXX/STNumberLabel/blob/master/LICENSE) for details. 16 | 17 | ## More Info 18 | - Have a question? Please [open an issue](https://github.com/StormXX/STNumberLabel/issues/new)! 19 | 20 | 21 | -------------------------------------------------------------------------------- /STNumberLabel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StormXX/STNumberLabel/798452b6ede5a924e553e16b04af5c33e3968de6/STNumberLabel.gif -------------------------------------------------------------------------------- /STNumberLabel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | EB29E0511BED9B1A002D9DEA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB29E0501BED9B1A002D9DEA /* AppDelegate.swift */; }; 11 | EB29E0531BED9B1A002D9DEA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB29E0521BED9B1A002D9DEA /* ViewController.swift */; }; 12 | EB29E0561BED9B1A002D9DEA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB29E0541BED9B1A002D9DEA /* Main.storyboard */; }; 13 | EB29E0581BED9B1A002D9DEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EB29E0571BED9B1A002D9DEA /* Assets.xcassets */; }; 14 | EB29E05B1BED9B1A002D9DEA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB29E0591BED9B1A002D9DEA /* LaunchScreen.storyboard */; }; 15 | EB29E0641BED9B5A002D9DEA /* STScrollNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB29E0631BED9B5A002D9DEA /* STScrollNumberView.swift */; }; 16 | EB2DE4A81BF07F11000766F8 /* CharacterExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2DE4A71BF07F11000766F8 /* CharacterExtension.swift */; }; 17 | EB6F9E4E1BEE594C0097630D /* STNumberLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB6F9E4D1BEE594C0097630D /* STNumberLabel.swift */; }; 18 | EBD69A791BF9BA35000AB73C /* UIViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBD69A781BF9BA35000AB73C /* UIViewExtension.swift */; }; 19 | EBDCFEA61BFEF26B0037332B /* STScrollNumberViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBDCFEA51BFEF26B0037332B /* STScrollNumberViewExtension.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | EB29E04D1BED9B1A002D9DEA /* STNumberLabel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = STNumberLabel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | EB29E0501BED9B1A002D9DEA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | EB29E0521BED9B1A002D9DEA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | EB29E0551BED9B1A002D9DEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | EB29E0571BED9B1A002D9DEA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | EB29E05A1BED9B1A002D9DEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | EB29E05C1BED9B1A002D9DEA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | EB29E0631BED9B5A002D9DEA /* STScrollNumberView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STScrollNumberView.swift; sourceTree = ""; }; 31 | EB2DE4A71BF07F11000766F8 /* CharacterExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterExtension.swift; sourceTree = ""; }; 32 | EB6F9E4D1BEE594C0097630D /* STNumberLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNumberLabel.swift; sourceTree = ""; }; 33 | EBD69A781BF9BA35000AB73C /* UIViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewExtension.swift; sourceTree = ""; }; 34 | EBDCFEA51BFEF26B0037332B /* STScrollNumberViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STScrollNumberViewExtension.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | EB29E04A1BED9B1A002D9DEA /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | EB29E0441BED9B1A002D9DEA = { 49 | isa = PBXGroup; 50 | children = ( 51 | EB29E04F1BED9B1A002D9DEA /* STNumberLabel */, 52 | EB29E04E1BED9B1A002D9DEA /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | EB29E04E1BED9B1A002D9DEA /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | EB29E04D1BED9B1A002D9DEA /* STNumberLabel.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | EB29E04F1BED9B1A002D9DEA /* STNumberLabel */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | EB2DE4A61BF07E6D000766F8 /* STNumberLabel */, 68 | EB29E0501BED9B1A002D9DEA /* AppDelegate.swift */, 69 | EB29E0521BED9B1A002D9DEA /* ViewController.swift */, 70 | EB29E0541BED9B1A002D9DEA /* Main.storyboard */, 71 | EB29E0571BED9B1A002D9DEA /* Assets.xcassets */, 72 | EB29E0591BED9B1A002D9DEA /* LaunchScreen.storyboard */, 73 | EB29E05C1BED9B1A002D9DEA /* Info.plist */, 74 | ); 75 | path = STNumberLabel; 76 | sourceTree = ""; 77 | }; 78 | EB29E0621BED9B1F002D9DEA /* Views */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | EB29E0631BED9B5A002D9DEA /* STScrollNumberView.swift */, 82 | EB6F9E4D1BEE594C0097630D /* STNumberLabel.swift */, 83 | ); 84 | name = Views; 85 | sourceTree = ""; 86 | }; 87 | EB2DE4A61BF07E6D000766F8 /* STNumberLabel */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | EB2DE4A91BF07F1F000766F8 /* Extension */, 91 | EB29E0621BED9B1F002D9DEA /* Views */, 92 | ); 93 | name = STNumberLabel; 94 | sourceTree = ""; 95 | }; 96 | EB2DE4A91BF07F1F000766F8 /* Extension */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | EB2DE4A71BF07F11000766F8 /* CharacterExtension.swift */, 100 | EBD69A781BF9BA35000AB73C /* UIViewExtension.swift */, 101 | EBDCFEA51BFEF26B0037332B /* STScrollNumberViewExtension.swift */, 102 | ); 103 | name = Extension; 104 | sourceTree = ""; 105 | }; 106 | /* End PBXGroup section */ 107 | 108 | /* Begin PBXNativeTarget section */ 109 | EB29E04C1BED9B1A002D9DEA /* STNumberLabel */ = { 110 | isa = PBXNativeTarget; 111 | buildConfigurationList = EB29E05F1BED9B1A002D9DEA /* Build configuration list for PBXNativeTarget "STNumberLabel" */; 112 | buildPhases = ( 113 | EB29E0491BED9B1A002D9DEA /* Sources */, 114 | EB29E04A1BED9B1A002D9DEA /* Frameworks */, 115 | EB29E04B1BED9B1A002D9DEA /* Resources */, 116 | ); 117 | buildRules = ( 118 | ); 119 | dependencies = ( 120 | ); 121 | name = STNumberLabel; 122 | productName = STNumberLabel; 123 | productReference = EB29E04D1BED9B1A002D9DEA /* STNumberLabel.app */; 124 | productType = "com.apple.product-type.application"; 125 | }; 126 | /* End PBXNativeTarget section */ 127 | 128 | /* Begin PBXProject section */ 129 | EB29E0451BED9B1A002D9DEA /* Project object */ = { 130 | isa = PBXProject; 131 | attributes = { 132 | LastSwiftUpdateCheck = 0710; 133 | LastUpgradeCheck = 0710; 134 | ORGANIZATIONNAME = Donggu; 135 | TargetAttributes = { 136 | EB29E04C1BED9B1A002D9DEA = { 137 | CreatedOnToolsVersion = 7.1; 138 | LastSwiftMigration = 0830; 139 | }; 140 | }; 141 | }; 142 | buildConfigurationList = EB29E0481BED9B1A002D9DEA /* Build configuration list for PBXProject "STNumberLabel" */; 143 | compatibilityVersion = "Xcode 3.2"; 144 | developmentRegion = English; 145 | hasScannedForEncodings = 0; 146 | knownRegions = ( 147 | en, 148 | Base, 149 | ); 150 | mainGroup = EB29E0441BED9B1A002D9DEA; 151 | productRefGroup = EB29E04E1BED9B1A002D9DEA /* Products */; 152 | projectDirPath = ""; 153 | projectRoot = ""; 154 | targets = ( 155 | EB29E04C1BED9B1A002D9DEA /* STNumberLabel */, 156 | ); 157 | }; 158 | /* End PBXProject section */ 159 | 160 | /* Begin PBXResourcesBuildPhase section */ 161 | EB29E04B1BED9B1A002D9DEA /* Resources */ = { 162 | isa = PBXResourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | EB29E05B1BED9B1A002D9DEA /* LaunchScreen.storyboard in Resources */, 166 | EB29E0581BED9B1A002D9DEA /* Assets.xcassets in Resources */, 167 | EB29E0561BED9B1A002D9DEA /* Main.storyboard in Resources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXSourcesBuildPhase section */ 174 | EB29E0491BED9B1A002D9DEA /* Sources */ = { 175 | isa = PBXSourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | EBD69A791BF9BA35000AB73C /* UIViewExtension.swift in Sources */, 179 | EB2DE4A81BF07F11000766F8 /* CharacterExtension.swift in Sources */, 180 | EBDCFEA61BFEF26B0037332B /* STScrollNumberViewExtension.swift in Sources */, 181 | EB29E0531BED9B1A002D9DEA /* ViewController.swift in Sources */, 182 | EB29E0641BED9B5A002D9DEA /* STScrollNumberView.swift in Sources */, 183 | EB6F9E4E1BEE594C0097630D /* STNumberLabel.swift in Sources */, 184 | EB29E0511BED9B1A002D9DEA /* AppDelegate.swift in Sources */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | /* End PBXSourcesBuildPhase section */ 189 | 190 | /* Begin PBXVariantGroup section */ 191 | EB29E0541BED9B1A002D9DEA /* Main.storyboard */ = { 192 | isa = PBXVariantGroup; 193 | children = ( 194 | EB29E0551BED9B1A002D9DEA /* Base */, 195 | ); 196 | name = Main.storyboard; 197 | sourceTree = ""; 198 | }; 199 | EB29E0591BED9B1A002D9DEA /* LaunchScreen.storyboard */ = { 200 | isa = PBXVariantGroup; 201 | children = ( 202 | EB29E05A1BED9B1A002D9DEA /* Base */, 203 | ); 204 | name = LaunchScreen.storyboard; 205 | sourceTree = ""; 206 | }; 207 | /* End PBXVariantGroup section */ 208 | 209 | /* Begin XCBuildConfiguration section */ 210 | EB29E05D1BED9B1A002D9DEA /* Debug */ = { 211 | isa = XCBuildConfiguration; 212 | buildSettings = { 213 | ALWAYS_SEARCH_USER_PATHS = NO; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 215 | CLANG_CXX_LIBRARY = "libc++"; 216 | CLANG_ENABLE_MODULES = YES; 217 | CLANG_ENABLE_OBJC_ARC = YES; 218 | CLANG_WARN_BOOL_CONVERSION = YES; 219 | CLANG_WARN_CONSTANT_CONVERSION = YES; 220 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 221 | CLANG_WARN_EMPTY_BODY = YES; 222 | CLANG_WARN_ENUM_CONVERSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 225 | CLANG_WARN_UNREACHABLE_CODE = YES; 226 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 227 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 228 | COPY_PHASE_STRIP = NO; 229 | DEBUG_INFORMATION_FORMAT = dwarf; 230 | ENABLE_STRICT_OBJC_MSGSEND = YES; 231 | ENABLE_TESTABILITY = YES; 232 | GCC_C_LANGUAGE_STANDARD = gnu99; 233 | GCC_DYNAMIC_NO_PIC = NO; 234 | GCC_NO_COMMON_BLOCKS = YES; 235 | GCC_OPTIMIZATION_LEVEL = 0; 236 | GCC_PREPROCESSOR_DEFINITIONS = ( 237 | "DEBUG=1", 238 | "$(inherited)", 239 | ); 240 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 241 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 242 | GCC_WARN_UNDECLARED_SELECTOR = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 244 | GCC_WARN_UNUSED_FUNCTION = YES; 245 | GCC_WARN_UNUSED_VARIABLE = YES; 246 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 247 | MTL_ENABLE_DEBUG_INFO = YES; 248 | ONLY_ACTIVE_ARCH = YES; 249 | SDKROOT = iphoneos; 250 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 251 | }; 252 | name = Debug; 253 | }; 254 | EB29E05E1BED9B1A002D9DEA /* Release */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | ALWAYS_SEARCH_USER_PATHS = NO; 258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 259 | CLANG_CXX_LIBRARY = "libc++"; 260 | CLANG_ENABLE_MODULES = YES; 261 | CLANG_ENABLE_OBJC_ARC = YES; 262 | CLANG_WARN_BOOL_CONVERSION = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 265 | CLANG_WARN_EMPTY_BODY = YES; 266 | CLANG_WARN_ENUM_CONVERSION = YES; 267 | CLANG_WARN_INT_CONVERSION = YES; 268 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 269 | CLANG_WARN_UNREACHABLE_CODE = YES; 270 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 271 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 272 | COPY_PHASE_STRIP = NO; 273 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 274 | ENABLE_NS_ASSERTIONS = NO; 275 | ENABLE_STRICT_OBJC_MSGSEND = YES; 276 | GCC_C_LANGUAGE_STANDARD = gnu99; 277 | GCC_NO_COMMON_BLOCKS = YES; 278 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 279 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 280 | GCC_WARN_UNDECLARED_SELECTOR = YES; 281 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 282 | GCC_WARN_UNUSED_FUNCTION = YES; 283 | GCC_WARN_UNUSED_VARIABLE = YES; 284 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 285 | MTL_ENABLE_DEBUG_INFO = NO; 286 | SDKROOT = iphoneos; 287 | VALIDATE_PRODUCT = YES; 288 | }; 289 | name = Release; 290 | }; 291 | EB29E0601BED9B1A002D9DEA /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | INFOPLIST_FILE = STNumberLabel/Info.plist; 296 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 297 | PRODUCT_BUNDLE_IDENTIFIER = com.Donggu.STNumberLabel; 298 | PRODUCT_NAME = "$(TARGET_NAME)"; 299 | SWIFT_VERSION = 3.0; 300 | }; 301 | name = Debug; 302 | }; 303 | EB29E0611BED9B1A002D9DEA /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | INFOPLIST_FILE = STNumberLabel/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 309 | PRODUCT_BUNDLE_IDENTIFIER = com.Donggu.STNumberLabel; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | SWIFT_VERSION = 3.0; 312 | }; 313 | name = Release; 314 | }; 315 | /* End XCBuildConfiguration section */ 316 | 317 | /* Begin XCConfigurationList section */ 318 | EB29E0481BED9B1A002D9DEA /* Build configuration list for PBXProject "STNumberLabel" */ = { 319 | isa = XCConfigurationList; 320 | buildConfigurations = ( 321 | EB29E05D1BED9B1A002D9DEA /* Debug */, 322 | EB29E05E1BED9B1A002D9DEA /* Release */, 323 | ); 324 | defaultConfigurationIsVisible = 0; 325 | defaultConfigurationName = Release; 326 | }; 327 | EB29E05F1BED9B1A002D9DEA /* Build configuration list for PBXNativeTarget "STNumberLabel" */ = { 328 | isa = XCConfigurationList; 329 | buildConfigurations = ( 330 | EB29E0601BED9B1A002D9DEA /* Debug */, 331 | EB29E0611BED9B1A002D9DEA /* Release */, 332 | ); 333 | defaultConfigurationIsVisible = 0; 334 | defaultConfigurationName = Release; 335 | }; 336 | /* End XCConfigurationList section */ 337 | }; 338 | rootObject = EB29E0451BED9B1A002D9DEA /* Project object */; 339 | } 340 | -------------------------------------------------------------------------------- /STNumberLabel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /STNumberLabel.xcodeproj/project.xcworkspace/xcuserdata/StormXX.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StormXX/STNumberLabel/798452b6ede5a924e553e16b04af5c33e3968de6/STNumberLabel.xcodeproj/project.xcworkspace/xcuserdata/StormXX.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /STNumberLabel.xcodeproj/xcuserdata/StormXX.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /STNumberLabel.xcodeproj/xcuserdata/StormXX.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | STNumberLabel.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | EB29E04C1BED9B1A002D9DEA 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /STNumberLabel/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/7. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /STNumberLabel/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /STNumberLabel/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /STNumberLabel/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 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /STNumberLabel/CharacterExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CharacterExtension.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/9. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension Character { 12 | func intValue() -> Int? { 13 | return Int(String(self)) 14 | } 15 | 16 | func utf8Value() -> UInt8 { 17 | for s in String(self).utf8 { 18 | return s 19 | } 20 | return 0 21 | } 22 | 23 | func utf16Value() -> UInt16 { 24 | for s in String(self).utf16 { 25 | return s 26 | } 27 | return 0 28 | } 29 | 30 | func unicodeValue() -> UInt32 { 31 | for s in String(self).unicodeScalars { 32 | return s.value 33 | } 34 | return 0 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /STNumberLabel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /STNumberLabel/STNumberLabel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNumberLabel.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/8. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class STNumberLabel: UIView { 12 | 13 | fileprivate var digit: Int! 14 | var scrollNumberViews: [STScrollNumberView]! 15 | 16 | internal var font: UIFont! 17 | internal var singleNumberSize: CGSize! 18 | internal var containerView: UIView! 19 | 20 | init(frame: CGRect, digit: Int, font: UIFont, singleNumberSize: CGSize) { 21 | self.digit = digit 22 | self.font = font 23 | self.singleNumberSize = singleNumberSize 24 | super.init(frame: frame) 25 | setupScrollNumberView() 26 | 27 | } 28 | 29 | func scrollToNumber(_ number: Int) { 30 | let numberString = String(number) 31 | let newDigit = numberString.characters.count 32 | 33 | var numberArray: [Int] = [] 34 | numberString.characters.forEach { (character) -> () in 35 | guard let intNumber = character.intValue() else { return } 36 | numberArray.append(intNumber) 37 | } 38 | 39 | if newDigit == digit { 40 | for i in 0.. Void in 49 | self.containerView!.center = CGPoint(x: self.containerView!.center.x + translate, y: self.containerView!.center.y) 50 | }, completion: { (finished) -> Void in 51 | if finished { 52 | self.constructNewContainerView(newDigit: newDigit, diff: diff, numberArray: numberArray) 53 | } 54 | }) 55 | } 56 | 57 | } 58 | 59 | // MARK: - helper 60 | fileprivate func setupScrollNumberView() { 61 | let containerViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: CGFloat(digit) * singleNumberSize.width, height: singleNumberSize.height)) 62 | containerView = UIView(frame: containerViewFrame) 63 | containerView.center = absoluteCenter 64 | 65 | scrollNumberViews = [] 66 | for i in 0.. 0 { 85 | for i in 0.. Void in 113 | newContainerView.alpha = 1.0 114 | self.containerView.alpha = 0.0 115 | }) { [unowned self](finished) -> Void in 116 | self.containerView.removeFromSuperview() 117 | self.containerView = newContainerView 118 | self.scrollNumberViews = newSrollNumberView 119 | self.digit = newDigit 120 | 121 | for i in 0.. 10 { 43 | scrollToNumber(0) 44 | return 45 | } 46 | if number == currentNumber { 47 | return 48 | } 49 | currentNumber = number 50 | UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveEaseOut, 51 | animations: { [weak self]() -> Void in 52 | guard let weakSelf = self else {return} 53 | weakSelf.scrollView.setContentOffset(CGPoint(x: 0, y: weakSelf.height*CGFloat(weakSelf.numberIndex[number])), animated: false) 54 | }, completion: nil) 55 | } 56 | 57 | required init?(coder aDecoder: NSCoder) { 58 | super.init(coder: aDecoder) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /STNumberLabel/STScrollNumberViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STScrollNumberViewExtension.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/20. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension STScrollNumberView { 12 | func deepCopy() -> STScrollNumberView { 13 | return STScrollNumberView(frame: frame, font: font, number: currentNumber) 14 | } 15 | } -------------------------------------------------------------------------------- /STNumberLabel/UIViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewExtension.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/16. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIView { 12 | var width: CGFloat { 13 | get { 14 | return frame.width 15 | } 16 | } 17 | 18 | var height: CGFloat { 19 | get { 20 | return frame.height 21 | } 22 | } 23 | 24 | var minX: CGFloat { 25 | get { 26 | return frame.minX 27 | } 28 | } 29 | 30 | var minY: CGFloat { 31 | get { 32 | return frame.minY 33 | } 34 | } 35 | 36 | var maxX: CGFloat { 37 | get { 38 | return frame.maxX 39 | } 40 | } 41 | 42 | var maxY: CGFloat { 43 | get { 44 | return frame.maxY 45 | } 46 | } 47 | 48 | var absoluteCenter: CGPoint { 49 | get { 50 | return CGPoint(x: width / 2, y: height / 2) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /STNumberLabel/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // STNumberLabel 4 | // 5 | // Created by DangGu on 15/11/7. 6 | // Copyright © 2015年 Donggu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | var numberlabel: STNumberLabel! 14 | @IBOutlet weak var textField: UITextField! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | numberlabel = STNumberLabel(frame: CGRect(x: 150, y: 200, width: 200, height: 50), digit: 4, font: UIFont.systemFont(ofSize: 22.0), singleNumberSize: CGSize(width: 20, height: 50)) 19 | numberlabel.center = CGPoint(x: view.width / 2, y: 200) 20 | view.addSubview(numberlabel); 21 | } 22 | 23 | override func viewDidAppear(_ animated: Bool) { 24 | super.viewDidAppear(animated) 25 | } 26 | 27 | override func didReceiveMemoryWarning() { 28 | super.didReceiveMemoryWarning() 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | @IBAction func buttonPressed(_ sender: AnyObject) { 33 | guard let text = textField.text, let number = Int(text) else { return } 34 | numberlabel.scrollToNumber(number) 35 | } 36 | 37 | } 38 | 39 | --------------------------------------------------------------------------------