├── .gitignore ├── JKCountDownLable.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── JKCountDownLable ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── JKCountDownLable │ ├── JKCountDownLable.h │ └── JKCountDownLable.m ├── ViewController.h ├── ViewController.m └── main.m ├── LICENSE ├── README.md └── demo.gif /.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 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /JKCountDownLable.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A2027A531B83283700E1D53D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A2027A521B83283700E1D53D /* main.m */; }; 11 | A2027A561B83283700E1D53D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A2027A551B83283700E1D53D /* AppDelegate.m */; }; 12 | A2027A591B83283700E1D53D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A2027A581B83283700E1D53D /* ViewController.m */; }; 13 | A2027A5C1B83283700E1D53D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A2027A5A1B83283700E1D53D /* Main.storyboard */; }; 14 | A2027A5E1B83283700E1D53D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A2027A5D1B83283700E1D53D /* Assets.xcassets */; }; 15 | A2027A611B83283700E1D53D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A2027A5F1B83283700E1D53D /* LaunchScreen.storyboard */; }; 16 | A2027A6B1B83285B00E1D53D /* JKCountDownLable.m in Sources */ = {isa = PBXBuildFile; fileRef = A2027A6A1B83285B00E1D53D /* JKCountDownLable.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | A2027A4E1B83283700E1D53D /* JKCountDownLable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JKCountDownLable.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | A2027A521B83283700E1D53D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | A2027A541B83283700E1D53D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | A2027A551B83283700E1D53D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | A2027A571B83283700E1D53D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | A2027A581B83283700E1D53D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | A2027A5B1B83283700E1D53D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | A2027A5D1B83283700E1D53D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | A2027A601B83283700E1D53D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | A2027A621B83283700E1D53D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | A2027A691B83285B00E1D53D /* JKCountDownLable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JKCountDownLable.h; sourceTree = ""; }; 31 | A2027A6A1B83285B00E1D53D /* JKCountDownLable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JKCountDownLable.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | A2027A4B1B83283700E1D53D /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | A2027A451B83283700E1D53D = { 46 | isa = PBXGroup; 47 | children = ( 48 | A2027A501B83283700E1D53D /* JKCountDownLable */, 49 | A2027A4F1B83283700E1D53D /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | A2027A4F1B83283700E1D53D /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | A2027A4E1B83283700E1D53D /* JKCountDownLable.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | A2027A501B83283700E1D53D /* JKCountDownLable */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | A2027A681B83284800E1D53D /* JKCountDownLable */, 65 | A2027A541B83283700E1D53D /* AppDelegate.h */, 66 | A2027A551B83283700E1D53D /* AppDelegate.m */, 67 | A2027A571B83283700E1D53D /* ViewController.h */, 68 | A2027A581B83283700E1D53D /* ViewController.m */, 69 | A2027A5A1B83283700E1D53D /* Main.storyboard */, 70 | A2027A5D1B83283700E1D53D /* Assets.xcassets */, 71 | A2027A5F1B83283700E1D53D /* LaunchScreen.storyboard */, 72 | A2027A621B83283700E1D53D /* Info.plist */, 73 | A2027A511B83283700E1D53D /* Supporting Files */, 74 | ); 75 | path = JKCountDownLable; 76 | sourceTree = ""; 77 | }; 78 | A2027A511B83283700E1D53D /* Supporting Files */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | A2027A521B83283700E1D53D /* main.m */, 82 | ); 83 | name = "Supporting Files"; 84 | sourceTree = ""; 85 | }; 86 | A2027A681B83284800E1D53D /* JKCountDownLable */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | A2027A691B83285B00E1D53D /* JKCountDownLable.h */, 90 | A2027A6A1B83285B00E1D53D /* JKCountDownLable.m */, 91 | ); 92 | path = JKCountDownLable; 93 | sourceTree = ""; 94 | }; 95 | /* End PBXGroup section */ 96 | 97 | /* Begin PBXNativeTarget section */ 98 | A2027A4D1B83283700E1D53D /* JKCountDownLable */ = { 99 | isa = PBXNativeTarget; 100 | buildConfigurationList = A2027A651B83283700E1D53D /* Build configuration list for PBXNativeTarget "JKCountDownLable" */; 101 | buildPhases = ( 102 | A2027A4A1B83283700E1D53D /* Sources */, 103 | A2027A4B1B83283700E1D53D /* Frameworks */, 104 | A2027A4C1B83283700E1D53D /* Resources */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = JKCountDownLable; 111 | productName = JKCountDownLable; 112 | productReference = A2027A4E1B83283700E1D53D /* JKCountDownLable.app */; 113 | productType = "com.apple.product-type.application"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | A2027A461B83283700E1D53D /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastUpgradeCheck = 0700; 122 | ORGANIZATIONNAME = Jakey; 123 | TargetAttributes = { 124 | A2027A4D1B83283700E1D53D = { 125 | CreatedOnToolsVersion = 7.0; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = A2027A491B83283700E1D53D /* Build configuration list for PBXProject "JKCountDownLable" */; 130 | compatibilityVersion = "Xcode 3.2"; 131 | developmentRegion = English; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = A2027A451B83283700E1D53D; 138 | productRefGroup = A2027A4F1B83283700E1D53D /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | A2027A4D1B83283700E1D53D /* JKCountDownLable */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | A2027A4C1B83283700E1D53D /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | A2027A611B83283700E1D53D /* LaunchScreen.storyboard in Resources */, 153 | A2027A5E1B83283700E1D53D /* Assets.xcassets in Resources */, 154 | A2027A5C1B83283700E1D53D /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | A2027A4A1B83283700E1D53D /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | A2027A591B83283700E1D53D /* ViewController.m in Sources */, 166 | A2027A561B83283700E1D53D /* AppDelegate.m in Sources */, 167 | A2027A531B83283700E1D53D /* main.m in Sources */, 168 | A2027A6B1B83285B00E1D53D /* JKCountDownLable.m in Sources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXSourcesBuildPhase section */ 173 | 174 | /* Begin PBXVariantGroup section */ 175 | A2027A5A1B83283700E1D53D /* Main.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | A2027A5B1B83283700E1D53D /* Base */, 179 | ); 180 | name = Main.storyboard; 181 | sourceTree = ""; 182 | }; 183 | A2027A5F1B83283700E1D53D /* LaunchScreen.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | A2027A601B83283700E1D53D /* Base */, 187 | ); 188 | name = LaunchScreen.storyboard; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | A2027A631B83283700E1D53D /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_UNREACHABLE_CODE = YES; 210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 211 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 212 | COPY_PHASE_STRIP = NO; 213 | DEBUG_INFORMATION_FORMAT = dwarf; 214 | ENABLE_STRICT_OBJC_MSGSEND = YES; 215 | ENABLE_TESTABILITY = YES; 216 | GCC_C_LANGUAGE_STANDARD = gnu99; 217 | GCC_DYNAMIC_NO_PIC = NO; 218 | GCC_NO_COMMON_BLOCKS = YES; 219 | GCC_OPTIMIZATION_LEVEL = 0; 220 | GCC_PREPROCESSOR_DEFINITIONS = ( 221 | "DEBUG=1", 222 | "$(inherited)", 223 | ); 224 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 225 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 226 | GCC_WARN_UNDECLARED_SELECTOR = YES; 227 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 228 | GCC_WARN_UNUSED_FUNCTION = YES; 229 | GCC_WARN_UNUSED_VARIABLE = YES; 230 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 231 | MTL_ENABLE_DEBUG_INFO = YES; 232 | ONLY_ACTIVE_ARCH = YES; 233 | SDKROOT = iphoneos; 234 | }; 235 | name = Debug; 236 | }; 237 | A2027A641B83283700E1D53D /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 242 | CLANG_CXX_LIBRARY = "libc++"; 243 | CLANG_ENABLE_MODULES = YES; 244 | CLANG_ENABLE_OBJC_ARC = YES; 245 | CLANG_WARN_BOOL_CONVERSION = YES; 246 | CLANG_WARN_CONSTANT_CONVERSION = YES; 247 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 248 | CLANG_WARN_EMPTY_BODY = YES; 249 | CLANG_WARN_ENUM_CONVERSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 252 | CLANG_WARN_UNREACHABLE_CODE = YES; 253 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 254 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 255 | COPY_PHASE_STRIP = NO; 256 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 257 | ENABLE_NS_ASSERTIONS = NO; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu99; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 263 | GCC_WARN_UNDECLARED_SELECTOR = YES; 264 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 265 | GCC_WARN_UNUSED_FUNCTION = YES; 266 | GCC_WARN_UNUSED_VARIABLE = YES; 267 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 268 | MTL_ENABLE_DEBUG_INFO = NO; 269 | SDKROOT = iphoneos; 270 | VALIDATE_PRODUCT = YES; 271 | }; 272 | name = Release; 273 | }; 274 | A2027A661B83283700E1D53D /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | INFOPLIST_FILE = JKCountDownLable/Info.plist; 279 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 280 | PRODUCT_BUNDLE_IDENTIFIER = org.skyfox.JKCountDownLable; 281 | PRODUCT_NAME = "$(TARGET_NAME)"; 282 | }; 283 | name = Debug; 284 | }; 285 | A2027A671B83283700E1D53D /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 289 | INFOPLIST_FILE = JKCountDownLable/Info.plist; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = org.skyfox.JKCountDownLable; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | }; 294 | name = Release; 295 | }; 296 | /* End XCBuildConfiguration section */ 297 | 298 | /* Begin XCConfigurationList section */ 299 | A2027A491B83283700E1D53D /* Build configuration list for PBXProject "JKCountDownLable" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | A2027A631B83283700E1D53D /* Debug */, 303 | A2027A641B83283700E1D53D /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | A2027A651B83283700E1D53D /* Build configuration list for PBXNativeTarget "JKCountDownLable" */ = { 309 | isa = XCConfigurationList; 310 | buildConfigurations = ( 311 | A2027A661B83283700E1D53D /* Debug */, 312 | A2027A671B83283700E1D53D /* Release */, 313 | ); 314 | defaultConfigurationIsVisible = 0; 315 | defaultConfigurationName = Release; 316 | }; 317 | /* End XCConfigurationList section */ 318 | }; 319 | rootObject = A2027A461B83283700E1D53D /* Project object */; 320 | } 321 | -------------------------------------------------------------------------------- /JKCountDownLable.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JKCountDownLable/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /JKCountDownLable/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /JKCountDownLable/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 | } -------------------------------------------------------------------------------- /JKCountDownLable/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 | -------------------------------------------------------------------------------- /JKCountDownLable/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /JKCountDownLable/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 | -------------------------------------------------------------------------------- /JKCountDownLable/JKCountDownLable/JKCountDownLable.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKCountDownLable.h 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import 10 | @class JKCountDownLable; 11 | 12 | typedef NSString* (^CountDownLableChange)(JKCountDownLable *countDownLable,NSDate *endTime,NSTimeInterval seconds,NSDictionary *DHMSInfo,NSString *defaultText); 13 | typedef NSString* (^countDownLableFinished)(JKCountDownLable *countDownLable,NSDate *endTime,NSTimeInterval seconds,NSString *defaultText); 14 | 15 | 16 | @interface JKCountDownLable : UILabel 17 | { 18 | NSTimer *_timer; 19 | NSDate *_endTime; 20 | NSDate *_beginTime; 21 | 22 | CountDownLableChange _countDownLableChange; 23 | countDownLableFinished _countDownLableFinished; 24 | } 25 | //倒计时开始时间 26 | - (NSDate*)beginTime; 27 | //倒计时结束时间 28 | - (NSDate*)endTime; 29 | //倒计时过去了N秒 30 | - (NSTimeInterval)secondsPassed; 31 | //倒计时还有N秒 32 | - (NSTimeInterval)secondsRemain; 33 | ///截止日期 34 | - (void)countDownWithDate:(NSDate*)date; 35 | ///距离当前时间timeInterval秒的截止日期 36 | - (void)countDownWithTimeInterval:(NSTimeInterval)timeInterval; 37 | 38 | - (void)countDownLableChange:(CountDownLableChange)countDownLableChange; 39 | 40 | - (void)countDownLableFinished:(CountDownLableChange)countDownLableFinished; 41 | 42 | ///根据秒获取天,时,分,秒信息 key分别是 D H M S,value为NSIntger的NSNumber类型. 43 | + (NSDictionary*)getDHMSInfoWithSeconds:(NSTimeInterval)seconds; 44 | @end 45 | -------------------------------------------------------------------------------- /JKCountDownLable/JKCountDownLable/JKCountDownLable.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKCountDownLable.m 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import "JKCountDownLable.h" 10 | @interface NSTimer (JKCountDownLabelBlocksSupport) 11 | + (NSTimer *)jkcdl_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 12 | block:(void(^)(void))block 13 | repeats:(BOOL)repeats; 14 | @end 15 | 16 | @implementation JKCountDownLable 17 | - (NSDate*)beginTime{ 18 | return _beginTime; 19 | } 20 | - (NSDate*)endTime{ 21 | return _endTime; 22 | } 23 | - (NSTimeInterval)secondsPassed{ 24 | return [[NSDate date] timeIntervalSinceDate:_beginTime]; 25 | } 26 | - (NSTimeInterval)secondsRemain{ 27 | return [_endTime timeIntervalSinceDate:[NSDate date]]; 28 | } 29 | - (void)changeText{ 30 | NSDate *date = [NSDate date]; 31 | 32 | NSTimeInterval deltaTime = [_endTime timeIntervalSinceDate:date]; 33 | 34 | NSDictionary *DHMSInfo = [[self class] getDHMSInfoWithSeconds:deltaTime]; 35 | 36 | NSInteger D = [[DHMSInfo objectForKey:@"D"] integerValue]; 37 | NSInteger H = [[DHMSInfo objectForKey:@"H"] integerValue]; 38 | NSInteger M = [[DHMSInfo objectForKey:@"M"] integerValue]; 39 | NSInteger S = [[DHMSInfo objectForKey:@"S"] integerValue]; 40 | 41 | NSString *defaultText = [NSString stringWithFormat:@"%0.3zd :%0.2zd : %0.2zd : %0.2zd", D,H,M,S]; 42 | 43 | 44 | if (deltaTime <=0.0) { 45 | [self stop]; 46 | return; 47 | }else{ 48 | if (_countDownLableChange) { 49 | self.text = _countDownLableChange(self,_endTime,deltaTime,DHMSInfo,defaultText); 50 | }else{ 51 | self.text = defaultText; 52 | } 53 | } 54 | } 55 | + (NSDictionary*)getDHMSInfoWithSeconds:(NSTimeInterval)seconds{ 56 | 57 | NSInteger day = seconds/86400; 58 | NSInteger hour = (seconds-(day*86400))/3600; 59 | NSInteger minute = (seconds-(day*86400)-(hour*3600))/60; 60 | NSInteger second = (seconds-(day*86400)-(hour*3600)-minute*60); 61 | 62 | return @{@"D":@(day),@"H":@(hour),@"M":@(minute),@"S":@(second)}; 63 | } 64 | 65 | - (void)countDownWithDate:(NSDate*)date{ 66 | [self stop]; 67 | _endTime = date; 68 | _beginTime= [NSDate date]; 69 | __weak typeof(self) weakSelf = self; 70 | _timer = [NSTimer jkcdl_scheduledTimerWithTimeInterval:1.0 block:^{ 71 | typeof(weakSelf) strongSelf = weakSelf; 72 | [strongSelf changeText]; 73 | } repeats:YES]; 74 | 75 | [[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes]; 76 | } 77 | - (void)countDownWithTimeInterval:(NSTimeInterval)timeInterval{ 78 | [self stop]; 79 | _endTime = [NSDate dateWithTimeIntervalSince1970:timeInterval]; 80 | _beginTime= [NSDate date]; 81 | __weak typeof(self) weakSelf = self; 82 | _timer = [NSTimer jkcdl_scheduledTimerWithTimeInterval:1.0 block:^{ 83 | typeof(weakSelf) strongSelf = weakSelf; 84 | [strongSelf changeText]; 85 | } repeats:YES]; 86 | [[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes]; 87 | } 88 | 89 | - (void)stop{ 90 | if (_timer) { 91 | if ([_timer respondsToSelector:@selector(isValid)]) 92 | { 93 | if ([_timer isValid]) 94 | { 95 | [_timer invalidate]; 96 | if (_countDownLableFinished) 97 | { 98 | dispatch_async(dispatch_get_main_queue(), ^{ 99 | self.text = _countDownLableFinished(self,_endTime,0,@"000 : 00 : 00 : 00"); 100 | }); 101 | } 102 | else 103 | { 104 | self.text= @"000 : 00 : 00 : 00"; 105 | } 106 | } 107 | } 108 | } 109 | } 110 | - (void)countDownLableChange:(CountDownLableChange)countDownLableChange{ 111 | _countDownLableChange = [countDownLableChange copy]; 112 | } 113 | - (void)countDownLableFinished:(CountDownLableChange)countDownLableFinished{ 114 | _countDownLableFinished = [countDownLableFinished copy]; 115 | } 116 | @end 117 | 118 | @implementation NSTimer (JKCountDownLabelBlocksSupport) 119 | + (NSTimer *)jkcdl_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 120 | block:(void(^)(void))block 121 | repeats:(BOOL)repeats 122 | { 123 | return [self scheduledTimerWithTimeInterval:interval 124 | target:self 125 | selector:@selector(jkcdl_blockInvoke:) 126 | userInfo:[block copy] 127 | repeats:repeats]; 128 | } 129 | + (void)jkcdl_blockInvoke:(NSTimer *)timer { 130 | void (^block)(void) = timer.userInfo; 131 | if(block) { 132 | block(); 133 | } 134 | } 135 | @end 136 | -------------------------------------------------------------------------------- /JKCountDownLable/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JKCountDownLable.h" 11 | @interface ViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet JKCountDownLable *countDownLable; 14 | - (IBAction)infoTouched:(id)sender; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /JKCountDownLable/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | // Do any additional setup after loading the view, typically from a nib. 21 | //设置最原始的text 22 | self.countDownLable.text = @"00 : 00 : 00"; 23 | [self.countDownLable countDownWithDate:[NSDate dateWithTimeIntervalSinceNow:666]]; 24 | 25 | // [self.countDownLable countDownWithTimeInterval:1470614888]; 26 | [self.countDownLable countDownLableChange:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval second,NSDictionary *DHMSInfo, NSString *defaultText) { 27 | 28 | //自己格式化 29 | NSInteger D = [[DHMSInfo objectForKey:@"D"] integerValue]; 30 | NSInteger H = [[DHMSInfo objectForKey:@"H"] integerValue]; 31 | NSInteger M = [[DHMSInfo objectForKey:@"M"] integerValue]; 32 | NSInteger S = [[DHMSInfo objectForKey:@"S"] integerValue]; 33 | 34 | return [NSString stringWithFormat:@"%0.2zd : %0.2zd : %0.2zd", H,M,S]; 35 | 36 | // //使用控件内的默认格式化后的文本 37 | // return defaultText; 38 | }]; 39 | [self.countDownLable countDownLableFinished:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval seconds, NSDictionary *DHMSInfo, NSString *defaultText) { 40 | //自定义倒计时结束标题 41 | return @"00 : 00 : 00"; 42 | //使用控件内的默认格式化后的文本 43 | //return defaultText; 44 | }]; 45 | 46 | } 47 | 48 | - (void)didReceiveMemoryWarning { 49 | [super didReceiveMemoryWarning]; 50 | // Dispose of any resources that can be recreated. 51 | } 52 | 53 | - (IBAction)infoTouched:(id)sender { 54 | NSLog(@"beginTime:%@",[self.countDownLable beginTime]); 55 | NSLog(@"endTime:%@",[self.countDownLable endTime]); 56 | 57 | NSLog(@"secondsPassed:%lf",[self.countDownLable secondsPassed]); 58 | NSLog(@"secondsRemain:%lf",[self.countDownLable secondsRemain]); 59 | } 60 | @end 61 | -------------------------------------------------------------------------------- /JKCountDownLable/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JKCountDownLable 4 | // 5 | // Created by Jakey on 15/8/18. 6 | // Copyright © 2015年 Jakey. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | # JKCountDownLable 2 | JKCountDownLable,子类化UILable实现iOS倒计时Lable,天,时,分,秒 3 | 4 | ## 代码方式使用 5 | 6 | JKCountDownLable *_countDownCode; 7 | _countDownCode = [JKCountDownLable alloc]initWithFrame: CGRectMake(81, 200, 108, 32)]; 8 | [self.view addSubview:_countDownCode]; 9 | 10 | //设置最原始的text 11 | _countDownCode.text = @"00 : 00 : 00"; 12 | 13 | //[_countDownCode countDownWithDate:[NSDate dateWithTimeIntervalSinceNow:864000]]; 14 | 15 | [_countDownCode countDownWithTimeInterval:1470614888]; 16 | 17 | [_countDownCode countDownLableChange:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval second,NSDictionary *DHMSInfo, NSString *defaultText) { 18 | 19 | //自己格式化 20 | NSInteger D = [[DHMSInfo objectForKey:@"D"] integerValue]; 21 | NSInteger H = [[DHMSInfo objectForKey:@"H"] integerValue]; 22 | NSInteger M = [[DHMSInfo objectForKey:@"M"] integerValue]; 23 | NSInteger S = [[DHMSInfo objectForKey:@"S"] integerValue]; 24 | 25 | return [NSString stringWithFormat:@"%0.2zd : %0.2zd : %0.2zd", H,M,S]; 26 | 27 | //使用控件内的默认格式化后的文本 28 | //return defaultText; 29 | }]; 30 | [_countDownCode countDownLableFinished:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval seconds, NSDictionary *DHMSInfo, NSString *defaultText) { 31 | //自定义倒计时结束标题 32 | return @"00 : 00 : 00"; 33 | //使用控件内的默认格式化后的文本 34 | //return defaultText; 35 | }]; 36 | 37 | ## xib方式使用 38 | 39 | @property (weak, nonatomic) IBOutlet JKCountDownLable *countDownXib; 40 | 41 | //设置最原始的text 42 | self.countDownXib.text = @"00 : 00 : 00"; 43 | [self.countDownXib countDownWithDate:[NSDate dateWithTimeIntervalSinceNow:864000]]; 44 | 45 | //[self.countDownXib countDownWithTimeInterval:1470614888]; 46 | 47 | [self.countDownXib countDownLableChange:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval second,NSDictionary *DHMSInfo, NSString *defaultText) { 48 | 49 | //自己格式化 50 | NSInteger D = [[DHMSInfo objectForKey:@"D"] integerValue]; 51 | NSInteger H = [[DHMSInfo objectForKey:@"H"] integerValue]; 52 | NSInteger M = [[DHMSInfo objectForKey:@"M"] integerValue]; 53 | NSInteger S = [[DHMSInfo objectForKey:@"S"] integerValue]; 54 | 55 | return [NSString stringWithFormat:@"%0.2zd : %0.2zd : %0.2zd", H,M,S]; 56 | 57 | // //使用控件内的默认格式化后的文本 58 | // return defaultText; 59 | }]; 60 | [self.countDownXib countDownLableFinished:^NSString *(JKCountDownLable *countDownLable, NSDate *endTime, NSTimeInterval seconds, NSDictionary *DHMSInfo, NSString *defaultText) { 61 | //自定义倒计时结束标题 62 | return @"00 : 00 : 00"; 63 | //使用控件内的默认格式化后的文本 64 | //return defaultText; 65 | }]; 66 | 67 | 68 | ## 效果图 69 | ![](https://raw.githubusercontent.com/shaojiankui/JKCountDownLable/master/demo.gif) 70 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaojiankui/JKCountDownLable/ce2104ecf1a9c59f7cd9d00eefaed8e74e734f74/demo.gif --------------------------------------------------------------------------------