├── .gitignore ├── LICENSE ├── MCNumberLabel.podspec ├── MCNumberLabel ├── MCNumberLabel.h └── MCNumberLabel.m ├── MCNumberLabelDemo ├── MCNumberLabelDemo.xcodeproj │ └── project.pbxproj ├── MCNumberLabelDemo │ ├── Base.lproj │ │ └── Main.storyboard │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── MCAppDelegate.h │ ├── MCAppDelegate.m │ ├── MCNumberLabelDemo-Info.plist │ ├── MCNumberLabelDemo-Prefix.pch │ ├── MCViewController.h │ ├── MCViewController.m │ ├── en.lproj │ │ └── InfoPlist.strings │ └── main.m └── MCNumberLabelDemoTests │ ├── MCNumberLabelDemoTests-Info.plist │ ├── MCNumberLabelDemoTests.m │ └── en.lproj │ └── InfoPlist.strings ├── README.md └── screenshot.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | .DS_Store 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | *.xcworkspace 16 | !default.xcworkspace 17 | xcuserdata 18 | profile 19 | *.moved-aside 20 | DerivedData 21 | .idea/ 22 | 23 | # CocoaPods 24 | Pods 25 | Podfile.lock 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Matthew Cheok 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 | -------------------------------------------------------------------------------- /MCNumberLabel.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'MCNumberLabel' 3 | s.version = '0.1.1' 4 | s.platform = :ios, '7.0' 5 | s.license = { :type => 'MIT', :file => 'LICENSE' } 6 | s.summary = 'Drop-in label control with the ability to animate digits.' 7 | s.homepage = 'https://github.com/matthewcheok/MCNumberLabel' 8 | s.author = { 'Matthew Cheok' => 'cheok.jz@gmail.com' } 9 | s.requires_arc = true 10 | s.source = { :git => 'https://github.com/matthewcheok/MCNumberLabel.git', :branch => 'master', :tag => s.version.to_s } 11 | s.source_files = 'MCNumberLabel/*.{h,m}' 12 | s.public_header_files = 'MCNumberLabel/MCNumberLabel.h' 13 | end 14 | -------------------------------------------------------------------------------- /MCNumberLabel/MCNumberLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCNumberLabel.h 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCNumberLabel : UILabel 12 | 13 | @property (strong, nonatomic) NSNumberFormatter *formatter; 14 | @property (strong, nonatomic) NSNumber *value; 15 | 16 | - (void)setValue:(NSNumber *)value animated:(BOOL)animated; 17 | - (void)setValue:(NSNumber *)value duration:(NSTimeInterval)duration; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /MCNumberLabel/MCNumberLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCNumberLabel.m 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import "MCNumberLabel.h" 10 | 11 | @interface MCNumberLabel () 12 | 13 | @property (strong, nonatomic) CADisplayLink *displayLink; 14 | @property (strong, nonatomic) NSNumber *startNumber; 15 | @property (strong, nonatomic) NSNumber *endNumber; 16 | 17 | @property (assign, nonatomic) CFTimeInterval startTime; 18 | @property (assign, nonatomic) NSTimeInterval duration; 19 | 20 | @end 21 | 22 | @implementation MCNumberLabel 23 | 24 | - (void)dealloc { 25 | [self.displayLink invalidate]; 26 | } 27 | 28 | - (void)setup { 29 | _formatter = [[NSNumberFormatter alloc] init]; 30 | } 31 | 32 | - (id)initWithFrame:(CGRect)frame { 33 | self = [super initWithFrame:frame]; 34 | if (self) { 35 | [self setup]; 36 | } 37 | return self; 38 | } 39 | 40 | - (id)initWithCoder:(NSCoder *)aDecoder { 41 | self = [super initWithCoder:aDecoder]; 42 | if (self) { 43 | [self setup]; 44 | } 45 | return self; 46 | } 47 | 48 | #pragma mark - Methods 49 | 50 | - (void)animateValue { 51 | CGFloat progress = ([self.displayLink timestamp] - self.startTime)/self.duration; 52 | if (progress >= 1) { 53 | [self setValue:self.endNumber]; 54 | } 55 | else { 56 | NSNumber *value = @(progress * [self.endNumber doubleValue] + (1-progress) * [self.startNumber doubleValue]); 57 | [super setText:[self.formatter stringFromNumber:value]]; 58 | } 59 | } 60 | 61 | #pragma mark - Properties 62 | 63 | - (void)setValue:(NSNumber *)value { 64 | _value = value; 65 | 66 | [self.displayLink invalidate]; 67 | self.displayLink = nil; 68 | 69 | [super setText:[self.formatter stringFromNumber:value]]; 70 | } 71 | 72 | - (void)setValue:(NSNumber *)value duration:(NSTimeInterval)duration { 73 | self.startNumber = [self.formatter numberFromString:self.text]; 74 | self.endNumber = value; 75 | 76 | self.duration = duration; 77 | self.startTime = CACurrentMediaTime(); 78 | 79 | [self.displayLink invalidate]; 80 | self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(animateValue)]; 81 | [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; 82 | } 83 | 84 | - (void)setValue:(NSNumber *)value animated:(BOOL)animated { 85 | if (animated) { 86 | [self setValue:value duration:0.35]; 87 | } 88 | else { 89 | [self setValue:value]; 90 | } 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 342CA2DF18D3ECC700EFA360 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2DE18D3ECC700EFA360 /* Foundation.framework */; }; 11 | 342CA2E118D3ECC700EFA360 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2E018D3ECC700EFA360 /* CoreGraphics.framework */; }; 12 | 342CA2E318D3ECC700EFA360 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2E218D3ECC700EFA360 /* UIKit.framework */; }; 13 | 342CA2E918D3ECC700EFA360 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 342CA2E718D3ECC700EFA360 /* InfoPlist.strings */; }; 14 | 342CA2EB18D3ECC700EFA360 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 342CA2EA18D3ECC700EFA360 /* main.m */; }; 15 | 342CA2EF18D3ECC700EFA360 /* MCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 342CA2EE18D3ECC700EFA360 /* MCAppDelegate.m */; }; 16 | 342CA2F218D3ECC700EFA360 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 342CA2F018D3ECC700EFA360 /* Main.storyboard */; }; 17 | 342CA2F518D3ECC700EFA360 /* MCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 342CA2F418D3ECC700EFA360 /* MCViewController.m */; }; 18 | 342CA2F718D3ECC700EFA360 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 342CA2F618D3ECC700EFA360 /* Images.xcassets */; }; 19 | 342CA2FE18D3ECC800EFA360 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2FD18D3ECC800EFA360 /* XCTest.framework */; }; 20 | 342CA2FF18D3ECC800EFA360 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2DE18D3ECC700EFA360 /* Foundation.framework */; }; 21 | 342CA30018D3ECC800EFA360 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342CA2E218D3ECC700EFA360 /* UIKit.framework */; }; 22 | 342CA30818D3ECC800EFA360 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 342CA30618D3ECC800EFA360 /* InfoPlist.strings */; }; 23 | 342CA30A18D3ECC800EFA360 /* MCNumberLabelDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 342CA30918D3ECC800EFA360 /* MCNumberLabelDemoTests.m */; }; 24 | 342CA31B18D3F8A800EFA360 /* MCNumberLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 342CA31A18D3F8A800EFA360 /* MCNumberLabel.m */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXContainerItemProxy section */ 28 | 342CA30118D3ECC800EFA360 /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = 342CA2D318D3ECC700EFA360 /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = 342CA2DA18D3ECC700EFA360; 33 | remoteInfo = MCNumberLabelDemo; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 342CA2DB18D3ECC700EFA360 /* MCNumberLabelDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MCNumberLabelDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 342CA2DE18D3ECC700EFA360 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 40 | 342CA2E018D3ECC700EFA360 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 41 | 342CA2E218D3ECC700EFA360 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 42 | 342CA2E618D3ECC700EFA360 /* MCNumberLabelDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MCNumberLabelDemo-Info.plist"; sourceTree = ""; }; 43 | 342CA2E818D3ECC700EFA360 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 44 | 342CA2EA18D3ECC700EFA360 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 45 | 342CA2EC18D3ECC700EFA360 /* MCNumberLabelDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MCNumberLabelDemo-Prefix.pch"; sourceTree = ""; }; 46 | 342CA2ED18D3ECC700EFA360 /* MCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAppDelegate.h; sourceTree = ""; }; 47 | 342CA2EE18D3ECC700EFA360 /* MCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCAppDelegate.m; sourceTree = ""; }; 48 | 342CA2F118D3ECC700EFA360 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 342CA2F318D3ECC700EFA360 /* MCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCViewController.h; sourceTree = ""; }; 50 | 342CA2F418D3ECC700EFA360 /* MCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCViewController.m; sourceTree = ""; }; 51 | 342CA2F618D3ECC700EFA360 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 52 | 342CA2FC18D3ECC800EFA360 /* MCNumberLabelDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCNumberLabelDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 342CA2FD18D3ECC800EFA360 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 54 | 342CA30518D3ECC800EFA360 /* MCNumberLabelDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MCNumberLabelDemoTests-Info.plist"; sourceTree = ""; }; 55 | 342CA30718D3ECC800EFA360 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 56 | 342CA30918D3ECC800EFA360 /* MCNumberLabelDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCNumberLabelDemoTests.m; sourceTree = ""; }; 57 | 342CA31918D3F8A800EFA360 /* MCNumberLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MCNumberLabel.h; path = ../../MCNumberLabel/MCNumberLabel.h; sourceTree = ""; }; 58 | 342CA31A18D3F8A800EFA360 /* MCNumberLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MCNumberLabel.m; path = ../../MCNumberLabel/MCNumberLabel.m; sourceTree = ""; }; 59 | /* End PBXFileReference section */ 60 | 61 | /* Begin PBXFrameworksBuildPhase section */ 62 | 342CA2D818D3ECC700EFA360 /* Frameworks */ = { 63 | isa = PBXFrameworksBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | 342CA2E118D3ECC700EFA360 /* CoreGraphics.framework in Frameworks */, 67 | 342CA2E318D3ECC700EFA360 /* UIKit.framework in Frameworks */, 68 | 342CA2DF18D3ECC700EFA360 /* Foundation.framework in Frameworks */, 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | 342CA2F918D3ECC800EFA360 /* Frameworks */ = { 73 | isa = PBXFrameworksBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | 342CA2FE18D3ECC800EFA360 /* XCTest.framework in Frameworks */, 77 | 342CA30018D3ECC800EFA360 /* UIKit.framework in Frameworks */, 78 | 342CA2FF18D3ECC800EFA360 /* Foundation.framework in Frameworks */, 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | /* End PBXFrameworksBuildPhase section */ 83 | 84 | /* Begin PBXGroup section */ 85 | 342CA2D218D3ECC700EFA360 = { 86 | isa = PBXGroup; 87 | children = ( 88 | 342CA2E418D3ECC700EFA360 /* MCNumberLabelDemo */, 89 | 342CA30318D3ECC800EFA360 /* MCNumberLabelDemoTests */, 90 | 342CA2DD18D3ECC700EFA360 /* Frameworks */, 91 | 342CA2DC18D3ECC700EFA360 /* Products */, 92 | ); 93 | sourceTree = ""; 94 | }; 95 | 342CA2DC18D3ECC700EFA360 /* Products */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 342CA2DB18D3ECC700EFA360 /* MCNumberLabelDemo.app */, 99 | 342CA2FC18D3ECC800EFA360 /* MCNumberLabelDemoTests.xctest */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | 342CA2DD18D3ECC700EFA360 /* Frameworks */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 342CA2DE18D3ECC700EFA360 /* Foundation.framework */, 108 | 342CA2E018D3ECC700EFA360 /* CoreGraphics.framework */, 109 | 342CA2E218D3ECC700EFA360 /* UIKit.framework */, 110 | 342CA2FD18D3ECC800EFA360 /* XCTest.framework */, 111 | ); 112 | name = Frameworks; 113 | sourceTree = ""; 114 | }; 115 | 342CA2E418D3ECC700EFA360 /* MCNumberLabelDemo */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 342CA31818D3ED6300EFA360 /* MCNumberLabel */, 119 | 342CA31318D3ED4000EFA360 /* App Delegate */, 120 | 342CA31418D3ED4A00EFA360 /* View Controllers */, 121 | 342CA2F618D3ECC700EFA360 /* Images.xcassets */, 122 | 342CA2E518D3ECC700EFA360 /* Supporting Files */, 123 | ); 124 | path = MCNumberLabelDemo; 125 | sourceTree = ""; 126 | }; 127 | 342CA2E518D3ECC700EFA360 /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 342CA2E618D3ECC700EFA360 /* MCNumberLabelDemo-Info.plist */, 131 | 342CA2E718D3ECC700EFA360 /* InfoPlist.strings */, 132 | 342CA2EA18D3ECC700EFA360 /* main.m */, 133 | 342CA2EC18D3ECC700EFA360 /* MCNumberLabelDemo-Prefix.pch */, 134 | ); 135 | name = "Supporting Files"; 136 | sourceTree = ""; 137 | }; 138 | 342CA30318D3ECC800EFA360 /* MCNumberLabelDemoTests */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 342CA30918D3ECC800EFA360 /* MCNumberLabelDemoTests.m */, 142 | 342CA30418D3ECC800EFA360 /* Supporting Files */, 143 | ); 144 | path = MCNumberLabelDemoTests; 145 | sourceTree = ""; 146 | }; 147 | 342CA30418D3ECC800EFA360 /* Supporting Files */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 342CA30518D3ECC800EFA360 /* MCNumberLabelDemoTests-Info.plist */, 151 | 342CA30618D3ECC800EFA360 /* InfoPlist.strings */, 152 | ); 153 | name = "Supporting Files"; 154 | sourceTree = ""; 155 | }; 156 | 342CA31318D3ED4000EFA360 /* App Delegate */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | 342CA2ED18D3ECC700EFA360 /* MCAppDelegate.h */, 160 | 342CA2EE18D3ECC700EFA360 /* MCAppDelegate.m */, 161 | ); 162 | name = "App Delegate"; 163 | sourceTree = ""; 164 | }; 165 | 342CA31418D3ED4A00EFA360 /* View Controllers */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 342CA2F018D3ECC700EFA360 /* Main.storyboard */, 169 | 342CA2F318D3ECC700EFA360 /* MCViewController.h */, 170 | 342CA2F418D3ECC700EFA360 /* MCViewController.m */, 171 | ); 172 | name = "View Controllers"; 173 | sourceTree = ""; 174 | }; 175 | 342CA31818D3ED6300EFA360 /* MCNumberLabel */ = { 176 | isa = PBXGroup; 177 | children = ( 178 | 342CA31918D3F8A800EFA360 /* MCNumberLabel.h */, 179 | 342CA31A18D3F8A800EFA360 /* MCNumberLabel.m */, 180 | ); 181 | name = MCNumberLabel; 182 | sourceTree = ""; 183 | }; 184 | /* End PBXGroup section */ 185 | 186 | /* Begin PBXNativeTarget section */ 187 | 342CA2DA18D3ECC700EFA360 /* MCNumberLabelDemo */ = { 188 | isa = PBXNativeTarget; 189 | buildConfigurationList = 342CA30D18D3ECC800EFA360 /* Build configuration list for PBXNativeTarget "MCNumberLabelDemo" */; 190 | buildPhases = ( 191 | 342CA2D718D3ECC700EFA360 /* Sources */, 192 | 342CA2D818D3ECC700EFA360 /* Frameworks */, 193 | 342CA2D918D3ECC700EFA360 /* Resources */, 194 | ); 195 | buildRules = ( 196 | ); 197 | dependencies = ( 198 | ); 199 | name = MCNumberLabelDemo; 200 | productName = MCNumberLabelDemo; 201 | productReference = 342CA2DB18D3ECC700EFA360 /* MCNumberLabelDemo.app */; 202 | productType = "com.apple.product-type.application"; 203 | }; 204 | 342CA2FB18D3ECC800EFA360 /* MCNumberLabelDemoTests */ = { 205 | isa = PBXNativeTarget; 206 | buildConfigurationList = 342CA31018D3ECC800EFA360 /* Build configuration list for PBXNativeTarget "MCNumberLabelDemoTests" */; 207 | buildPhases = ( 208 | 342CA2F818D3ECC800EFA360 /* Sources */, 209 | 342CA2F918D3ECC800EFA360 /* Frameworks */, 210 | 342CA2FA18D3ECC800EFA360 /* Resources */, 211 | ); 212 | buildRules = ( 213 | ); 214 | dependencies = ( 215 | 342CA30218D3ECC800EFA360 /* PBXTargetDependency */, 216 | ); 217 | name = MCNumberLabelDemoTests; 218 | productName = MCNumberLabelDemoTests; 219 | productReference = 342CA2FC18D3ECC800EFA360 /* MCNumberLabelDemoTests.xctest */; 220 | productType = "com.apple.product-type.bundle.unit-test"; 221 | }; 222 | /* End PBXNativeTarget section */ 223 | 224 | /* Begin PBXProject section */ 225 | 342CA2D318D3ECC700EFA360 /* Project object */ = { 226 | isa = PBXProject; 227 | attributes = { 228 | CLASSPREFIX = MC; 229 | LastUpgradeCheck = 0510; 230 | ORGANIZATIONNAME = "Matthew Cheok"; 231 | TargetAttributes = { 232 | 342CA2FB18D3ECC800EFA360 = { 233 | TestTargetID = 342CA2DA18D3ECC700EFA360; 234 | }; 235 | }; 236 | }; 237 | buildConfigurationList = 342CA2D618D3ECC700EFA360 /* Build configuration list for PBXProject "MCNumberLabelDemo" */; 238 | compatibilityVersion = "Xcode 3.2"; 239 | developmentRegion = English; 240 | hasScannedForEncodings = 0; 241 | knownRegions = ( 242 | en, 243 | Base, 244 | ); 245 | mainGroup = 342CA2D218D3ECC700EFA360; 246 | productRefGroup = 342CA2DC18D3ECC700EFA360 /* Products */; 247 | projectDirPath = ""; 248 | projectRoot = ""; 249 | targets = ( 250 | 342CA2DA18D3ECC700EFA360 /* MCNumberLabelDemo */, 251 | 342CA2FB18D3ECC800EFA360 /* MCNumberLabelDemoTests */, 252 | ); 253 | }; 254 | /* End PBXProject section */ 255 | 256 | /* Begin PBXResourcesBuildPhase section */ 257 | 342CA2D918D3ECC700EFA360 /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 342CA2F718D3ECC700EFA360 /* Images.xcassets in Resources */, 262 | 342CA2E918D3ECC700EFA360 /* InfoPlist.strings in Resources */, 263 | 342CA2F218D3ECC700EFA360 /* Main.storyboard in Resources */, 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | 342CA2FA18D3ECC800EFA360 /* Resources */ = { 268 | isa = PBXResourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | 342CA30818D3ECC800EFA360 /* InfoPlist.strings in Resources */, 272 | ); 273 | runOnlyForDeploymentPostprocessing = 0; 274 | }; 275 | /* End PBXResourcesBuildPhase section */ 276 | 277 | /* Begin PBXSourcesBuildPhase section */ 278 | 342CA2D718D3ECC700EFA360 /* Sources */ = { 279 | isa = PBXSourcesBuildPhase; 280 | buildActionMask = 2147483647; 281 | files = ( 282 | 342CA2EF18D3ECC700EFA360 /* MCAppDelegate.m in Sources */, 283 | 342CA2F518D3ECC700EFA360 /* MCViewController.m in Sources */, 284 | 342CA2EB18D3ECC700EFA360 /* main.m in Sources */, 285 | 342CA31B18D3F8A800EFA360 /* MCNumberLabel.m in Sources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | 342CA2F818D3ECC800EFA360 /* Sources */ = { 290 | isa = PBXSourcesBuildPhase; 291 | buildActionMask = 2147483647; 292 | files = ( 293 | 342CA30A18D3ECC800EFA360 /* MCNumberLabelDemoTests.m in Sources */, 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | /* End PBXSourcesBuildPhase section */ 298 | 299 | /* Begin PBXTargetDependency section */ 300 | 342CA30218D3ECC800EFA360 /* PBXTargetDependency */ = { 301 | isa = PBXTargetDependency; 302 | target = 342CA2DA18D3ECC700EFA360 /* MCNumberLabelDemo */; 303 | targetProxy = 342CA30118D3ECC800EFA360 /* PBXContainerItemProxy */; 304 | }; 305 | /* End PBXTargetDependency section */ 306 | 307 | /* Begin PBXVariantGroup section */ 308 | 342CA2E718D3ECC700EFA360 /* InfoPlist.strings */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | 342CA2E818D3ECC700EFA360 /* en */, 312 | ); 313 | name = InfoPlist.strings; 314 | sourceTree = ""; 315 | }; 316 | 342CA2F018D3ECC700EFA360 /* Main.storyboard */ = { 317 | isa = PBXVariantGroup; 318 | children = ( 319 | 342CA2F118D3ECC700EFA360 /* Base */, 320 | ); 321 | name = Main.storyboard; 322 | sourceTree = ""; 323 | }; 324 | 342CA30618D3ECC800EFA360 /* InfoPlist.strings */ = { 325 | isa = PBXVariantGroup; 326 | children = ( 327 | 342CA30718D3ECC800EFA360 /* en */, 328 | ); 329 | name = InfoPlist.strings; 330 | sourceTree = ""; 331 | }; 332 | /* End PBXVariantGroup section */ 333 | 334 | /* Begin XCBuildConfiguration section */ 335 | 342CA30B18D3ECC800EFA360 /* Debug */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ALWAYS_SEARCH_USER_PATHS = NO; 339 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 340 | CLANG_CXX_LIBRARY = "libc++"; 341 | CLANG_ENABLE_MODULES = YES; 342 | CLANG_ENABLE_OBJC_ARC = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_CONSTANT_CONVERSION = YES; 345 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 346 | CLANG_WARN_EMPTY_BODY = YES; 347 | CLANG_WARN_ENUM_CONVERSION = YES; 348 | CLANG_WARN_INT_CONVERSION = YES; 349 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 350 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 351 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 352 | COPY_PHASE_STRIP = NO; 353 | GCC_C_LANGUAGE_STANDARD = gnu99; 354 | GCC_DYNAMIC_NO_PIC = NO; 355 | GCC_OPTIMIZATION_LEVEL = 0; 356 | GCC_PREPROCESSOR_DEFINITIONS = ( 357 | "DEBUG=1", 358 | "$(inherited)", 359 | ); 360 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 361 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 362 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 363 | GCC_WARN_UNDECLARED_SELECTOR = YES; 364 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 365 | GCC_WARN_UNUSED_FUNCTION = YES; 366 | GCC_WARN_UNUSED_VARIABLE = YES; 367 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 368 | ONLY_ACTIVE_ARCH = YES; 369 | SDKROOT = iphoneos; 370 | }; 371 | name = Debug; 372 | }; 373 | 342CA30C18D3ECC800EFA360 /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 377 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 378 | CLANG_CXX_LIBRARY = "libc++"; 379 | CLANG_ENABLE_MODULES = YES; 380 | CLANG_ENABLE_OBJC_ARC = YES; 381 | CLANG_WARN_BOOL_CONVERSION = YES; 382 | CLANG_WARN_CONSTANT_CONVERSION = YES; 383 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 384 | CLANG_WARN_EMPTY_BODY = YES; 385 | CLANG_WARN_ENUM_CONVERSION = YES; 386 | CLANG_WARN_INT_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 389 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 390 | COPY_PHASE_STRIP = YES; 391 | ENABLE_NS_ASSERTIONS = NO; 392 | GCC_C_LANGUAGE_STANDARD = gnu99; 393 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 394 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 395 | GCC_WARN_UNDECLARED_SELECTOR = YES; 396 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 397 | GCC_WARN_UNUSED_FUNCTION = YES; 398 | GCC_WARN_UNUSED_VARIABLE = YES; 399 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 400 | SDKROOT = iphoneos; 401 | VALIDATE_PRODUCT = YES; 402 | }; 403 | name = Release; 404 | }; 405 | 342CA30E18D3ECC800EFA360 /* Debug */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 409 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 410 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 411 | GCC_PREFIX_HEADER = "MCNumberLabelDemo/MCNumberLabelDemo-Prefix.pch"; 412 | INFOPLIST_FILE = "MCNumberLabelDemo/MCNumberLabelDemo-Info.plist"; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | WRAPPER_EXTENSION = app; 415 | }; 416 | name = Debug; 417 | }; 418 | 342CA30F18D3ECC800EFA360 /* Release */ = { 419 | isa = XCBuildConfiguration; 420 | buildSettings = { 421 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 422 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 423 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 424 | GCC_PREFIX_HEADER = "MCNumberLabelDemo/MCNumberLabelDemo-Prefix.pch"; 425 | INFOPLIST_FILE = "MCNumberLabelDemo/MCNumberLabelDemo-Info.plist"; 426 | PRODUCT_NAME = "$(TARGET_NAME)"; 427 | WRAPPER_EXTENSION = app; 428 | }; 429 | name = Release; 430 | }; 431 | 342CA31118D3ECC800EFA360 /* Debug */ = { 432 | isa = XCBuildConfiguration; 433 | buildSettings = { 434 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MCNumberLabelDemo.app/MCNumberLabelDemo"; 435 | FRAMEWORK_SEARCH_PATHS = ( 436 | "$(SDKROOT)/Developer/Library/Frameworks", 437 | "$(inherited)", 438 | "$(DEVELOPER_FRAMEWORKS_DIR)", 439 | ); 440 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 441 | GCC_PREFIX_HEADER = "MCNumberLabelDemo/MCNumberLabelDemo-Prefix.pch"; 442 | GCC_PREPROCESSOR_DEFINITIONS = ( 443 | "DEBUG=1", 444 | "$(inherited)", 445 | ); 446 | INFOPLIST_FILE = "MCNumberLabelDemoTests/MCNumberLabelDemoTests-Info.plist"; 447 | PRODUCT_NAME = "$(TARGET_NAME)"; 448 | TEST_HOST = "$(BUNDLE_LOADER)"; 449 | WRAPPER_EXTENSION = xctest; 450 | }; 451 | name = Debug; 452 | }; 453 | 342CA31218D3ECC800EFA360 /* Release */ = { 454 | isa = XCBuildConfiguration; 455 | buildSettings = { 456 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MCNumberLabelDemo.app/MCNumberLabelDemo"; 457 | FRAMEWORK_SEARCH_PATHS = ( 458 | "$(SDKROOT)/Developer/Library/Frameworks", 459 | "$(inherited)", 460 | "$(DEVELOPER_FRAMEWORKS_DIR)", 461 | ); 462 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 463 | GCC_PREFIX_HEADER = "MCNumberLabelDemo/MCNumberLabelDemo-Prefix.pch"; 464 | INFOPLIST_FILE = "MCNumberLabelDemoTests/MCNumberLabelDemoTests-Info.plist"; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | TEST_HOST = "$(BUNDLE_LOADER)"; 467 | WRAPPER_EXTENSION = xctest; 468 | }; 469 | name = Release; 470 | }; 471 | /* End XCBuildConfiguration section */ 472 | 473 | /* Begin XCConfigurationList section */ 474 | 342CA2D618D3ECC700EFA360 /* Build configuration list for PBXProject "MCNumberLabelDemo" */ = { 475 | isa = XCConfigurationList; 476 | buildConfigurations = ( 477 | 342CA30B18D3ECC800EFA360 /* Debug */, 478 | 342CA30C18D3ECC800EFA360 /* Release */, 479 | ); 480 | defaultConfigurationIsVisible = 0; 481 | defaultConfigurationName = Release; 482 | }; 483 | 342CA30D18D3ECC800EFA360 /* Build configuration list for PBXNativeTarget "MCNumberLabelDemo" */ = { 484 | isa = XCConfigurationList; 485 | buildConfigurations = ( 486 | 342CA30E18D3ECC800EFA360 /* Debug */, 487 | 342CA30F18D3ECC800EFA360 /* Release */, 488 | ); 489 | defaultConfigurationIsVisible = 0; 490 | }; 491 | 342CA31018D3ECC800EFA360 /* Build configuration list for PBXNativeTarget "MCNumberLabelDemoTests" */ = { 492 | isa = XCConfigurationList; 493 | buildConfigurations = ( 494 | 342CA31118D3ECC800EFA360 /* Debug */, 495 | 342CA31218D3ECC800EFA360 /* Release */, 496 | ); 497 | defaultConfigurationIsVisible = 0; 498 | }; 499 | /* End XCConfigurationList section */ 500 | }; 501 | rootObject = 342CA2D318D3ECC700EFA360 /* Project object */; 502 | } 503 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 36 | 46 | 56 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCAppDelegate.h 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCAppDelegate.m 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import "MCAppDelegate.h" 10 | 11 | @implementation MCAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 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 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 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 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCNumberLabelDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.matthewcheok.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCNumberLabelDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCViewController.h 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/MCViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCViewController.m 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import "MCViewController.h" 10 | #import "MCNumberLabel.h" 11 | 12 | @import CoreText; 13 | 14 | @interface MCViewController () 15 | 16 | @property (weak, nonatomic) IBOutlet MCNumberLabel *numberLabel; 17 | 18 | @end 19 | 20 | @implementation MCViewController 21 | 22 | #pragma mark - Methods 23 | 24 | - (IBAction)handleFirstButton:(id)sender { 25 | [self.numberLabel setValue:@(10) animated:YES]; 26 | } 27 | 28 | - (IBAction)handleSecondButton:(id)sender { 29 | [self.numberLabel setValue:@(100) animated:YES]; 30 | } 31 | 32 | - (IBAction)handleThirdButton:(id)sender { 33 | [self.numberLabel setValue:@(1000) animated:YES]; 34 | } 35 | 36 | - (IBAction)handleFourthButton:(id)sender { 37 | [self.numberLabel setValue:@(10000) animated:YES]; 38 | } 39 | 40 | #pragma mark - UIViewController 41 | 42 | - (void)viewDidLoad { 43 | [super viewDidLoad]; 44 | // Do any additional setup after loading the view, typically from a nib. 45 | 46 | // use proportional spaced fonts 47 | UIFont *const existingFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; 48 | UIFontDescriptor *const existingDescriptor = [existingFont fontDescriptor]; 49 | 50 | NSDictionary *const fontAttributes = @{ 51 | // Here comes that array of dictionaries each containing UIFontFeatureTypeIdentifierKey 52 | // and UIFontFeatureSelectorIdentifierKey that the reference mentions. 53 | UIFontDescriptorFeatureSettingsAttribute: @[ 54 | @{ 55 | UIFontFeatureTypeIdentifierKey: @(kNumberSpacingType), 56 | UIFontFeatureSelectorIdentifierKey: @(kProportionalNumbersSelector) 57 | }, 58 | @{ 59 | UIFontFeatureTypeIdentifierKey: @(kCharacterAlternativesType), 60 | UIFontFeatureSelectorIdentifierKey: @(1) 61 | }] 62 | }; 63 | 64 | UIFontDescriptor *const proportionalDescriptor = [existingDescriptor fontDescriptorByAddingAttributes:fontAttributes]; 65 | UIFont *const proportionalFont = [UIFont fontWithDescriptor:proportionalDescriptor size:64]; 66 | self.numberLabel.font = proportionalFont; 67 | 68 | // thousands separator 69 | self.numberLabel.formatter.usesGroupingSeparator = YES; 70 | self.numberLabel.formatter.groupingSeparator = @","; 71 | self.numberLabel.formatter.groupingSize = 3; 72 | } 73 | 74 | - (void)didReceiveMemoryWarning { 75 | [super didReceiveMemoryWarning]; 76 | // Dispose of any resources that can be recreated. 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MCNumberLabelDemo 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "MCAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([MCAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemoTests/MCNumberLabelDemoTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.matthewcheok.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemoTests/MCNumberLabelDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCNumberLabelDemoTests.m 3 | // MCNumberLabelDemoTests 4 | // 5 | // Created by Matthew Cheok on 15/3/14. 6 | // Copyright (c) 2014 Matthew Cheok. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCNumberLabelDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation MCNumberLabelDemoTests 16 | 17 | - (void)setUp 18 | { 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 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /MCNumberLabelDemo/MCNumberLabelDemoTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MCNumberLabel 2 | ===================== 3 | 4 | Drop-in label control with the ability to animate digits. 5 | 6 | 7 | ##Screenshot 8 | ![Screenshot](https://raw.github.com/matthewcheok/MCNumberLabel/master/screenshot.gif "Example of MCNumberLabel") 9 | 10 | ## Installation 11 | 12 | Add the following to your [CocoaPods](http://cocoapods.org/) Podfile 13 | 14 | pod 'MCNumberLabel' 15 | 16 | or clone as a git submodule, 17 | 18 | or just copy files in the ```MCNumberLabel``` folder into your project. 19 | 20 | ## Using MCNumberLabel 21 | 22 | Simply call methods `-setValue:animated:` or `-setValue:duration:` to animate digits. 23 | 24 | [self.numberLabel setValue:@(100) animated:YES]; 25 | 26 | or 27 | 28 | [self.numberLabel setValue:@(100) duration:0.5]; 29 | 30 | ## Configuring the NSNumberFormatter 31 | 32 | You can specify more granular options for displaying numbers using the `formatter` property on MCNumberLabel. 33 | 34 | An example for configuring a thousands separator is as follows: 35 | 36 | self.numberLabel.formatter.usesGroupingSeparator = YES; 37 | self.numberLabel.formatter.groupingSeparator = @","; 38 | self.numberLabel.formatter.groupingSize = 3; 39 | 40 | ## Using Proportional Numbers 41 | 42 | You can present more readable digits by using proportional numbers. The following snippet from WWDC 2013 Session 223 would configure such fonts: 43 | 44 | UIFont *const existingFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; 45 | UIFontDescriptor *const existingDescriptor = [existingFont fontDescriptor]; 46 | 47 | NSDictionary *const fontAttributes = @{ 48 | // Here comes that array of dictionaries each containing UIFontFeatureTypeIdentifierKey 49 | // and UIFontFeatureSelectorIdentifierKey that the reference mentions. 50 | UIFontDescriptorFeatureSettingsAttribute: @[ 51 | @{ 52 | UIFontFeatureTypeIdentifierKey: @(kNumberSpacingType), 53 | UIFontFeatureSelectorIdentifierKey: @(kProportionalNumbersSelector) 54 | }, 55 | @{ 56 | UIFontFeatureTypeIdentifierKey: @(kCharacterAlternativesType), 57 | UIFontFeatureSelectorIdentifierKey: @(1) 58 | }] 59 | }; 60 | 61 | UIFontDescriptor *const proportionalDescriptor = [existingDescriptor fontDescriptorByAddingAttributes:fontAttributes]; 62 | UIFont *const proportionalFont = [UIFont fontWithDescriptor:proportionalDescriptor size:64]; 63 | self.numberLabel.font = proportionalFont; 64 | 65 | ## License 66 | 67 | MCNumberLabel is under the MIT license. 68 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matthewcheok/MCNumberLabel/3fad4e7ee48187fd44ed14ede10eea17b36ca3f6/screenshot.gif --------------------------------------------------------------------------------