├── .gitignore ├── LICENSE ├── MZTimerLabel.podspec ├── MZTimerLabel.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── MZTimerLabel.xcscheme ├── MZTimerLabel ├── Info.plist ├── MZTimerLabel.h └── MZTimerLabel.m ├── MZTimerLabelDemo ├── MZTimerLabelDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── MZTimerLabelDemo │ ├── DemoView.xib │ ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json │ ├── MZTLAppDelegate.h │ ├── MZTLAppDelegate.m │ ├── MZTLViewController.h │ ├── MZTLViewController.m │ ├── MZTimerLabelDemo-Info.plist │ ├── MZTimerLabelDemo-Prefix.pch │ ├── MainView.xib │ ├── en.lproj │ ├── InfoPlist.strings │ └── Main.strings │ └── main.m ├── MZTimerLabel_Demo.png ├── MZTimerLabel_Demo2.png ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 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 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 mineschan 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 | -------------------------------------------------------------------------------- /MZTimerLabel.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "MZTimerLabel" 4 | s.version = "0.5.4" 5 | s.summary = "A handy class to use UILabel as a countdown timer or stopwatch just like in Apple Clock App." 6 | s.description = "MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple Clock App with just 2 lines of code. MZTimerLabel also provides delegate method for you to define the action when the timer finished." 7 | 8 | s.homepage = "https://github.com/mineschan/MZTimerLabel" 9 | s.screenshots = "https://raw.githubusercontent.com/mineschan/MZTimerLabel/master/MZTimerLabel_Demo.png" 10 | s.license = { :type => 'MIT', :file => 'LICENSE' } 11 | s.author = { "MineS Chan" => "mineschan@gmail.com" } 12 | 13 | s.ios.deployment_target = '6.0' 14 | s.tvos.deployment_target = '9.0' 15 | 16 | s.source = { :git => "https://github.com/mineschan/MZTimerLabel.git", :tag => s.version.to_s } 17 | 18 | s.source_files = 'Classes', 'MZTimerLabel/*.{h,m}' 19 | s.exclude_files = 'Classes/Exclude' 20 | 21 | s.requires_arc = true 22 | 23 | end 24 | -------------------------------------------------------------------------------- /MZTimerLabel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 40A965371AD4CDB700B2D499 /* MZTimerLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 40A965111AD4CAF500B2D499 /* MZTimerLabel.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 40A965381AD4CDBD00B2D499 /* MZTimerLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 40A965121AD4CAF500B2D499 /* MZTimerLabel.m */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXContainerItemProxy section */ 15 | 40A965271AD4CB5F00B2D499 /* PBXContainerItemProxy */ = { 16 | isa = PBXContainerItemProxy; 17 | containerPortal = 40A9650A1AD4CA9F00B2D499 /* Project object */; 18 | proxyType = 1; 19 | remoteGlobalIDString = 40A965191AD4CB5F00B2D499; 20 | remoteInfo = MZTimerLabel; 21 | }; 22 | /* End PBXContainerItemProxy section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 40A965111AD4CAF500B2D499 /* MZTimerLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MZTimerLabel.h; sourceTree = ""; }; 26 | 40A965121AD4CAF500B2D499 /* MZTimerLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MZTimerLabel.m; sourceTree = ""; }; 27 | 40A9651A1AD4CB5F00B2D499 /* MZTimerLabel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MZTimerLabel.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 40A9651E1AD4CB5F00B2D499 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | 40A965251AD4CB5F00B2D499 /* MZTimerLabelTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MZTimerLabelTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | /* End PBXFileReference section */ 31 | 32 | /* Begin PBXFrameworksBuildPhase section */ 33 | 40A965161AD4CB5F00B2D499 /* Frameworks */ = { 34 | isa = PBXFrameworksBuildPhase; 35 | buildActionMask = 2147483647; 36 | files = ( 37 | ); 38 | runOnlyForDeploymentPostprocessing = 0; 39 | }; 40 | 40A965221AD4CB5F00B2D499 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 40A965091AD4CA9F00B2D499 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 40A9651C1AD4CB5F00B2D499 /* MZTimerLabel */, 54 | 40A9651B1AD4CB5F00B2D499 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 40A9651B1AD4CB5F00B2D499 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 40A9651A1AD4CB5F00B2D499 /* MZTimerLabel.framework */, 62 | 40A965251AD4CB5F00B2D499 /* MZTimerLabelTests.xctest */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | 40A9651C1AD4CB5F00B2D499 /* MZTimerLabel */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 40A965111AD4CAF500B2D499 /* MZTimerLabel.h */, 71 | 40A965121AD4CAF500B2D499 /* MZTimerLabel.m */, 72 | 40A9651D1AD4CB5F00B2D499 /* Supporting Files */, 73 | ); 74 | path = MZTimerLabel; 75 | sourceTree = ""; 76 | }; 77 | 40A9651D1AD4CB5F00B2D499 /* Supporting Files */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 40A9651E1AD4CB5F00B2D499 /* Info.plist */, 81 | ); 82 | name = "Supporting Files"; 83 | sourceTree = ""; 84 | }; 85 | /* End PBXGroup section */ 86 | 87 | /* Begin PBXHeadersBuildPhase section */ 88 | 40A965171AD4CB5F00B2D499 /* Headers */ = { 89 | isa = PBXHeadersBuildPhase; 90 | buildActionMask = 2147483647; 91 | files = ( 92 | 40A965371AD4CDB700B2D499 /* MZTimerLabel.h in Headers */, 93 | ); 94 | runOnlyForDeploymentPostprocessing = 0; 95 | }; 96 | /* End PBXHeadersBuildPhase section */ 97 | 98 | /* Begin PBXNativeTarget section */ 99 | 40A965191AD4CB5F00B2D499 /* MZTimerLabel */ = { 100 | isa = PBXNativeTarget; 101 | buildConfigurationList = 40A9652E1AD4CB5F00B2D499 /* Build configuration list for PBXNativeTarget "MZTimerLabel" */; 102 | buildPhases = ( 103 | 40A965151AD4CB5F00B2D499 /* Sources */, 104 | 40A965161AD4CB5F00B2D499 /* Frameworks */, 105 | 40A965171AD4CB5F00B2D499 /* Headers */, 106 | 40A965181AD4CB5F00B2D499 /* Resources */, 107 | ); 108 | buildRules = ( 109 | ); 110 | dependencies = ( 111 | ); 112 | name = MZTimerLabel; 113 | productName = MZTimerLabel; 114 | productReference = 40A9651A1AD4CB5F00B2D499 /* MZTimerLabel.framework */; 115 | productType = "com.apple.product-type.framework"; 116 | }; 117 | 40A965241AD4CB5F00B2D499 /* MZTimerLabelTests */ = { 118 | isa = PBXNativeTarget; 119 | buildConfigurationList = 40A965311AD4CB5F00B2D499 /* Build configuration list for PBXNativeTarget "MZTimerLabelTests" */; 120 | buildPhases = ( 121 | 40A965211AD4CB5F00B2D499 /* Sources */, 122 | 40A965221AD4CB5F00B2D499 /* Frameworks */, 123 | 40A965231AD4CB5F00B2D499 /* Resources */, 124 | ); 125 | buildRules = ( 126 | ); 127 | dependencies = ( 128 | 40A965281AD4CB5F00B2D499 /* PBXTargetDependency */, 129 | ); 130 | name = MZTimerLabelTests; 131 | productName = MZTimerLabelTests; 132 | productReference = 40A965251AD4CB5F00B2D499 /* MZTimerLabelTests.xctest */; 133 | productType = "com.apple.product-type.bundle.unit-test"; 134 | }; 135 | /* End PBXNativeTarget section */ 136 | 137 | /* Begin PBXProject section */ 138 | 40A9650A1AD4CA9F00B2D499 /* Project object */ = { 139 | isa = PBXProject; 140 | attributes = { 141 | LastUpgradeCheck = 0620; 142 | TargetAttributes = { 143 | 40A965191AD4CB5F00B2D499 = { 144 | CreatedOnToolsVersion = 6.2; 145 | }; 146 | 40A965241AD4CB5F00B2D499 = { 147 | CreatedOnToolsVersion = 6.2; 148 | }; 149 | }; 150 | }; 151 | buildConfigurationList = 40A9650D1AD4CA9F00B2D499 /* Build configuration list for PBXProject "MZTimerLabel" */; 152 | compatibilityVersion = "Xcode 3.2"; 153 | developmentRegion = English; 154 | hasScannedForEncodings = 0; 155 | knownRegions = ( 156 | en, 157 | ); 158 | mainGroup = 40A965091AD4CA9F00B2D499; 159 | productRefGroup = 40A9651B1AD4CB5F00B2D499 /* Products */; 160 | projectDirPath = ""; 161 | projectRoot = ""; 162 | targets = ( 163 | 40A965191AD4CB5F00B2D499 /* MZTimerLabel */, 164 | 40A965241AD4CB5F00B2D499 /* MZTimerLabelTests */, 165 | ); 166 | }; 167 | /* End PBXProject section */ 168 | 169 | /* Begin PBXResourcesBuildPhase section */ 170 | 40A965181AD4CB5F00B2D499 /* Resources */ = { 171 | isa = PBXResourcesBuildPhase; 172 | buildActionMask = 2147483647; 173 | files = ( 174 | ); 175 | runOnlyForDeploymentPostprocessing = 0; 176 | }; 177 | 40A965231AD4CB5F00B2D499 /* Resources */ = { 178 | isa = PBXResourcesBuildPhase; 179 | buildActionMask = 2147483647; 180 | files = ( 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXResourcesBuildPhase section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | 40A965151AD4CB5F00B2D499 /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 40A965381AD4CDBD00B2D499 /* MZTimerLabel.m in Sources */, 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | 40A965211AD4CB5F00B2D499 /* Sources */ = { 196 | isa = PBXSourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | /* End PBXSourcesBuildPhase section */ 203 | 204 | /* Begin PBXTargetDependency section */ 205 | 40A965281AD4CB5F00B2D499 /* PBXTargetDependency */ = { 206 | isa = PBXTargetDependency; 207 | target = 40A965191AD4CB5F00B2D499 /* MZTimerLabel */; 208 | targetProxy = 40A965271AD4CB5F00B2D499 /* PBXContainerItemProxy */; 209 | }; 210 | /* End PBXTargetDependency section */ 211 | 212 | /* Begin XCBuildConfiguration section */ 213 | 40A9650E1AD4CA9F00B2D499 /* Debug */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | }; 217 | name = Debug; 218 | }; 219 | 40A9650F1AD4CA9F00B2D499 /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | }; 223 | name = Release; 224 | }; 225 | 40A9652F1AD4CB5F00B2D499 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_WARN_BOOL_CONVERSION = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_EMPTY_BODY = YES; 237 | CLANG_WARN_ENUM_CONVERSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_UNREACHABLE_CODE = YES; 241 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 242 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 243 | COPY_PHASE_STRIP = NO; 244 | CURRENT_PROJECT_VERSION = 1; 245 | DEFINES_MODULE = YES; 246 | DYLIB_COMPATIBILITY_VERSION = 1; 247 | DYLIB_CURRENT_VERSION = 1; 248 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | GCC_C_LANGUAGE_STANDARD = gnu99; 251 | GCC_DYNAMIC_NO_PIC = NO; 252 | GCC_OPTIMIZATION_LEVEL = 0; 253 | GCC_PREPROCESSOR_DEFINITIONS = ( 254 | "DEBUG=1", 255 | "$(inherited)", 256 | ); 257 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | INFOPLIST_FILE = MZTimerLabel/Info.plist; 265 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 266 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 268 | MTL_ENABLE_DEBUG_INFO = YES; 269 | ONLY_ACTIVE_ARCH = YES; 270 | PRODUCT_NAME = "$(TARGET_NAME)"; 271 | SDKROOT = iphoneos; 272 | SKIP_INSTALL = YES; 273 | TARGETED_DEVICE_FAMILY = "1,2"; 274 | VERSIONING_SYSTEM = "apple-generic"; 275 | VERSION_INFO_PREFIX = ""; 276 | }; 277 | name = Debug; 278 | }; 279 | 40A965301AD4CB5F00B2D499 /* Release */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ALWAYS_SEARCH_USER_PATHS = NO; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_WARN_BOOL_CONVERSION = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 294 | CLANG_WARN_UNREACHABLE_CODE = YES; 295 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 296 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 297 | COPY_PHASE_STRIP = NO; 298 | CURRENT_PROJECT_VERSION = 1; 299 | DEFINES_MODULE = YES; 300 | DYLIB_COMPATIBILITY_VERSION = 1; 301 | DYLIB_CURRENT_VERSION = 1; 302 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 303 | ENABLE_NS_ASSERTIONS = NO; 304 | ENABLE_STRICT_OBJC_MSGSEND = YES; 305 | GCC_C_LANGUAGE_STANDARD = gnu99; 306 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 307 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 308 | GCC_WARN_UNDECLARED_SELECTOR = YES; 309 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 310 | GCC_WARN_UNUSED_FUNCTION = YES; 311 | GCC_WARN_UNUSED_VARIABLE = YES; 312 | INFOPLIST_FILE = MZTimerLabel/Info.plist; 313 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 314 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 315 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 316 | MTL_ENABLE_DEBUG_INFO = NO; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SDKROOT = iphoneos; 319 | SKIP_INSTALL = YES; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | VALIDATE_PRODUCT = YES; 322 | VERSIONING_SYSTEM = "apple-generic"; 323 | VERSION_INFO_PREFIX = ""; 324 | }; 325 | name = Release; 326 | }; 327 | 40A965321AD4CB5F00B2D499 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ALWAYS_SEARCH_USER_PATHS = NO; 331 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 332 | CLANG_CXX_LIBRARY = "libc++"; 333 | CLANG_ENABLE_MODULES = YES; 334 | CLANG_ENABLE_OBJC_ARC = YES; 335 | CLANG_WARN_BOOL_CONVERSION = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 | CLANG_WARN_EMPTY_BODY = YES; 339 | CLANG_WARN_ENUM_CONVERSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN_UNREACHABLE_CODE = YES; 343 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 344 | COPY_PHASE_STRIP = NO; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | FRAMEWORK_SEARCH_PATHS = ( 347 | "$(SDKROOT)/Developer/Library/Frameworks", 348 | "$(inherited)", 349 | ); 350 | GCC_C_LANGUAGE_STANDARD = gnu99; 351 | GCC_DYNAMIC_NO_PIC = NO; 352 | GCC_OPTIMIZATION_LEVEL = 0; 353 | GCC_PREPROCESSOR_DEFINITIONS = ( 354 | "DEBUG=1", 355 | "$(inherited)", 356 | ); 357 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | INFOPLIST_FILE = MZTimerLabelTests/Info.plist; 365 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 366 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 367 | MTL_ENABLE_DEBUG_INFO = YES; 368 | ONLY_ACTIVE_ARCH = YES; 369 | PRODUCT_NAME = "$(TARGET_NAME)"; 370 | SDKROOT = iphoneos; 371 | }; 372 | name = Debug; 373 | }; 374 | 40A965331AD4CB5F00B2D499 /* Release */ = { 375 | isa = XCBuildConfiguration; 376 | buildSettings = { 377 | ALWAYS_SEARCH_USER_PATHS = NO; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BOOL_CONVERSION = YES; 383 | CLANG_WARN_CONSTANT_CONVERSION = YES; 384 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 385 | CLANG_WARN_EMPTY_BODY = YES; 386 | CLANG_WARN_ENUM_CONVERSION = YES; 387 | CLANG_WARN_INT_CONVERSION = YES; 388 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 389 | CLANG_WARN_UNREACHABLE_CODE = YES; 390 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 391 | COPY_PHASE_STRIP = NO; 392 | ENABLE_NS_ASSERTIONS = NO; 393 | ENABLE_STRICT_OBJC_MSGSEND = YES; 394 | FRAMEWORK_SEARCH_PATHS = ( 395 | "$(SDKROOT)/Developer/Library/Frameworks", 396 | "$(inherited)", 397 | ); 398 | GCC_C_LANGUAGE_STANDARD = gnu99; 399 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 400 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 401 | GCC_WARN_UNDECLARED_SELECTOR = YES; 402 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 403 | GCC_WARN_UNUSED_FUNCTION = YES; 404 | GCC_WARN_UNUSED_VARIABLE = YES; 405 | INFOPLIST_FILE = MZTimerLabelTests/Info.plist; 406 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 407 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 408 | MTL_ENABLE_DEBUG_INFO = NO; 409 | PRODUCT_NAME = "$(TARGET_NAME)"; 410 | SDKROOT = iphoneos; 411 | VALIDATE_PRODUCT = YES; 412 | }; 413 | name = Release; 414 | }; 415 | /* End XCBuildConfiguration section */ 416 | 417 | /* Begin XCConfigurationList section */ 418 | 40A9650D1AD4CA9F00B2D499 /* Build configuration list for PBXProject "MZTimerLabel" */ = { 419 | isa = XCConfigurationList; 420 | buildConfigurations = ( 421 | 40A9650E1AD4CA9F00B2D499 /* Debug */, 422 | 40A9650F1AD4CA9F00B2D499 /* Release */, 423 | ); 424 | defaultConfigurationIsVisible = 0; 425 | defaultConfigurationName = Release; 426 | }; 427 | 40A9652E1AD4CB5F00B2D499 /* Build configuration list for PBXNativeTarget "MZTimerLabel" */ = { 428 | isa = XCConfigurationList; 429 | buildConfigurations = ( 430 | 40A9652F1AD4CB5F00B2D499 /* Debug */, 431 | 40A965301AD4CB5F00B2D499 /* Release */, 432 | ); 433 | defaultConfigurationIsVisible = 0; 434 | defaultConfigurationName = Release; 435 | }; 436 | 40A965311AD4CB5F00B2D499 /* Build configuration list for PBXNativeTarget "MZTimerLabelTests" */ = { 437 | isa = XCConfigurationList; 438 | buildConfigurations = ( 439 | 40A965321AD4CB5F00B2D499 /* Debug */, 440 | 40A965331AD4CB5F00B2D499 /* Release */, 441 | ); 442 | defaultConfigurationIsVisible = 0; 443 | defaultConfigurationName = Release; 444 | }; 445 | /* End XCConfigurationList section */ 446 | }; 447 | rootObject = 40A9650A1AD4CA9F00B2D499 /* Project object */; 448 | } 449 | -------------------------------------------------------------------------------- /MZTimerLabel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MZTimerLabel.xcodeproj/xcshareddata/xcschemes/MZTimerLabel.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /MZTimerLabel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | mineschan.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /MZTimerLabel/MZTimerLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // MZTimerLabel.h 3 | // Version 0.5.1 4 | // Created by MineS Chan on 2013-10-16 5 | // Updated 2014-12-15 6 | 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | 9 | // Copyright (c) 2014 MineS Chan 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | #import 30 | 31 | 32 | /********************************************** 33 | MZTimerLabel TimerType Enum 34 | **********************************************/ 35 | typedef enum{ 36 | MZTimerLabelTypeStopWatch, 37 | MZTimerLabelTypeTimer 38 | }MZTimerLabelType; 39 | 40 | /********************************************** 41 | Delegate Methods 42 | @optional 43 | 44 | - timerLabel:finshedCountDownTimerWithTimeWithTime: 45 | ** MZTimerLabel Delegate method for finish of countdown timer 46 | 47 | - timerLabel:countingTo:timertype: 48 | ** MZTimerLabel Delegate method for monitering the current counting progress 49 | 50 | - timerlabel:customTextToDisplayAtTime: 51 | ** MZTimerLabel Delegate method for overriding the text displaying at the time, implement this for your very custom display formmat 52 | **********************************************/ 53 | 54 | @class MZTimerLabel; 55 | @protocol MZTimerLabelDelegate 56 | @optional 57 | -(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime; 58 | -(void)timerLabel:(MZTimerLabel*)timerLabel countingTo:(NSTimeInterval)time timertype:(MZTimerLabelType)timerType; 59 | -(NSString*)timerLabel:(MZTimerLabel*)timerLabel customTextToDisplayAtTime:(NSTimeInterval)time; 60 | -(NSAttributedString*)timerLabel:(MZTimerLabel*)timerLabel customAttributedTextToDisplayAtTime:(NSTimeInterval)time; 61 | @end 62 | 63 | /********************************************** 64 | MZTimerLabel Class Defination 65 | **********************************************/ 66 | 67 | @interface MZTimerLabel : UILabel; 68 | 69 | /*Delegate for finish of countdown timer */ 70 | @property (nonatomic,weak) id delegate; 71 | 72 | /*Time format wish to display in label*/ 73 | @property (nonatomic,copy) NSString *timeFormat; 74 | 75 | /*Target label obejct, default self if you do not initWithLabel nor set*/ 76 | @property (nonatomic,strong) UILabel *timeLabel; 77 | 78 | /*Used for replace text in range */ 79 | @property (nonatomic, assign) NSRange textRange; 80 | 81 | @property (nonatomic, strong) NSDictionary *attributedDictionaryForTextInRange; 82 | 83 | /*Type to choose from stopwatch or timer*/ 84 | @property (assign) MZTimerLabelType timerType; 85 | 86 | /*Is The Timer Running?*/ 87 | @property (assign,readonly) BOOL counting; 88 | 89 | /*Do you want to reset the Timer after countdown?*/ 90 | @property (assign) BOOL resetTimerAfterFinish; 91 | 92 | /*Do you want the timer to count beyond the HH limit from 0-23 e.g. 25:23:12 (HH:mm:ss) */ 93 | @property (assign,nonatomic) BOOL shouldCountBeyondHHLimit; 94 | 95 | #if NS_BLOCKS_AVAILABLE 96 | @property (copy) void (^endedBlock)(NSTimeInterval); 97 | #endif 98 | 99 | 100 | /*--------Init methods to choose*/ 101 | -(id)initWithTimerType:(MZTimerLabelType)theType; 102 | -(id)initWithLabel:(UILabel*)theLabel andTimerType:(MZTimerLabelType)theType; 103 | -(id)initWithLabel:(UILabel*)theLabel; 104 | /*--------designated Initializer*/ 105 | -(id)initWithFrame:(CGRect)frame label:(UILabel*)theLabel andTimerType:(MZTimerLabelType)theType; 106 | 107 | /*--------Timer control methods to use*/ 108 | -(void)start; 109 | #if NS_BLOCKS_AVAILABLE 110 | -(void)startWithEndingBlock:(void(^)(NSTimeInterval countTime))end; //use it if you are not going to use delegate 111 | #endif 112 | -(void)pause; 113 | -(void)reset; 114 | 115 | /*--------Setter methods*/ 116 | -(void)setCountDownTime:(NSTimeInterval)time; 117 | -(void)setStopWatchTime:(NSTimeInterval)time; 118 | -(void)setCountDownToDate:(NSDate*)date; 119 | 120 | -(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd; 121 | 122 | /*--------Getter methods*/ 123 | - (NSTimeInterval)getTimeCounted; 124 | - (NSTimeInterval)getTimeRemaining; 125 | - (NSTimeInterval)getCountDownTime; 126 | 127 | 128 | 129 | 130 | 131 | @end 132 | 133 | 134 | -------------------------------------------------------------------------------- /MZTimerLabel/MZTimerLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // MZTimerLabel.h 3 | // Version 0.5.1 4 | // Created by MineS Chan on 2013-10-16 5 | // Updated 2014-12-15 6 | 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | 9 | // Copyright (c) 2014 MineS Chan 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining a copy 12 | // of this software and associated documentation files (the "Software"), to deal 13 | // in the Software without restriction, including without limitation the rights 14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | // copies of the Software, and to permit persons to whom the Software is 16 | // furnished to do so, subject to the following conditions: 17 | // 18 | // The above copyright notice and this permission notice shall be included in 19 | // all copies or substantial portions of the Software. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | 29 | #import "MZTimerLabel.h" 30 | 31 | 32 | #define kDefaultTimeFormat @"HH:mm:ss" 33 | #define kHourFormatReplace @"!!!*" 34 | #define kDefaultFireIntervalNormal 0.1 35 | #define kDefaultFireIntervalHighUse 0.01 36 | #define kDefaultTimerType MZTimerLabelTypeStopWatch 37 | @interface MZTimerLabel(){ 38 | 39 | NSTimeInterval timeUserValue; 40 | NSDate *startCountDate; 41 | NSDate *pausedTime; 42 | NSDate *date1970; 43 | NSDate *timeToCountOff; 44 | } 45 | 46 | @property (strong) NSTimer *timer; 47 | @property (nonatomic,strong) NSDateFormatter *dateFormatter; 48 | 49 | - (void)setup; 50 | - (void)updateLabel; 51 | 52 | @end 53 | 54 | #pragma mark - Initialize method 55 | 56 | @implementation MZTimerLabel 57 | 58 | @synthesize timeFormat = _timeFormat; 59 | 60 | - (void)dealloc { 61 | if (_timer) { 62 | [_timer invalidate]; 63 | } 64 | } 65 | 66 | - (id)initWithTimerType:(MZTimerLabelType)theType { 67 | return [self initWithFrame:CGRectZero label:nil andTimerType:theType]; 68 | } 69 | 70 | - (id)initWithLabel:(UILabel *)theLabel andTimerType:(MZTimerLabelType)theType { 71 | return [self initWithFrame:CGRectZero label:theLabel andTimerType:theType]; 72 | } 73 | 74 | - (id)initWithLabel:(UILabel*)theLabel { 75 | return [self initWithFrame:CGRectZero label:theLabel andTimerType:kDefaultTimerType]; 76 | } 77 | 78 | - (id)initWithFrame:(CGRect)frame { 79 | return [self initWithFrame:frame label:nil andTimerType:kDefaultTimerType]; 80 | } 81 | 82 | -(id)initWithFrame:(CGRect)frame label:(UILabel*)theLabel andTimerType:(MZTimerLabelType)theType { 83 | self = [super initWithFrame:frame]; 84 | if (self) { 85 | self.timeLabel = theLabel; 86 | self.timerType = theType; 87 | [self setup]; 88 | } 89 | return self; 90 | } 91 | 92 | - (id)initWithCoder:(NSCoder *)aDecoder 93 | { 94 | self = [super initWithCoder:aDecoder]; 95 | if (self) { 96 | [self setup]; 97 | } 98 | return self; 99 | } 100 | 101 | #pragma mark - Cleanup 102 | 103 | - (void) removeFromSuperview { 104 | if (_timer) { 105 | [_timer invalidate]; 106 | _timer = nil; 107 | } 108 | 109 | [super removeFromSuperview]; 110 | } 111 | 112 | #pragma mark - Getter and Setter Method 113 | 114 | - (void)setStopWatchTime:(NSTimeInterval)time{ 115 | 116 | timeUserValue = (time < 0) ? 0 : time; 117 | if(timeUserValue > 0){ 118 | startCountDate = [[NSDate date] dateByAddingTimeInterval:-timeUserValue]; 119 | pausedTime = [NSDate date]; 120 | [self updateLabel]; 121 | } 122 | } 123 | 124 | - (void)setCountDownTime:(NSTimeInterval)time{ 125 | 126 | timeUserValue = (time < 0)? 0 : time; 127 | timeToCountOff = [date1970 dateByAddingTimeInterval:timeUserValue]; 128 | [self updateLabel]; 129 | } 130 | 131 | -(void)setCountDownToDate:(NSDate*)date{ 132 | NSTimeInterval timeLeft = (int)[date timeIntervalSinceDate:[NSDate date]]; 133 | 134 | if (timeLeft > 0) { 135 | timeUserValue = timeLeft; 136 | timeToCountOff = [date1970 dateByAddingTimeInterval:timeLeft]; 137 | }else{ 138 | timeUserValue = 0; 139 | timeToCountOff = [date1970 dateByAddingTimeInterval:0]; 140 | } 141 | [self updateLabel]; 142 | 143 | } 144 | 145 | - (void)setTimeFormat:(NSString *)timeFormat{ 146 | 147 | if ([timeFormat length] != 0) { 148 | _timeFormat = timeFormat; 149 | self.dateFormatter.dateFormat = timeFormat; 150 | } 151 | [self updateLabel]; 152 | } 153 | 154 | - (NSString*)timeFormat 155 | { 156 | if ([_timeFormat length] == 0 || _timeFormat == nil) { 157 | _timeFormat = kDefaultTimeFormat; 158 | } 159 | 160 | return _timeFormat; 161 | } 162 | 163 | - (NSDateFormatter*)dateFormatter{ 164 | 165 | if (_dateFormatter == nil) { 166 | _dateFormatter = [[NSDateFormatter alloc] init]; 167 | _dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; 168 | [_dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 169 | _dateFormatter.dateFormat = self.timeFormat; 170 | } 171 | return _dateFormatter; 172 | } 173 | 174 | - (UILabel*)timeLabel 175 | { 176 | if (_timeLabel == nil) { 177 | _timeLabel = self; 178 | } 179 | return _timeLabel; 180 | } 181 | 182 | 183 | -(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd 184 | { 185 | if (_timerType == MZTimerLabelTypeTimer) { 186 | [self setCountDownTime:timeToAdd + timeUserValue]; 187 | }else if (_timerType == MZTimerLabelTypeStopWatch) { 188 | NSDate *newStartDate = [startCountDate dateByAddingTimeInterval:-timeToAdd]; 189 | if([[NSDate date] timeIntervalSinceDate:newStartDate] <= 0) { 190 | //prevent less than 0 191 | startCountDate = [NSDate date]; 192 | }else{ 193 | startCountDate = newStartDate; 194 | } 195 | } 196 | [self updateLabel]; 197 | } 198 | 199 | 200 | - (NSTimeInterval)getTimeCounted 201 | { 202 | if(!startCountDate) return 0; 203 | NSTimeInterval countedTime = [[NSDate date] timeIntervalSinceDate:startCountDate]; 204 | 205 | if(pausedTime != nil){ 206 | NSTimeInterval pauseCountedTime = [[NSDate date] timeIntervalSinceDate:pausedTime]; 207 | countedTime -= pauseCountedTime; 208 | } 209 | return countedTime; 210 | } 211 | 212 | - (NSTimeInterval)getTimeRemaining { 213 | 214 | if (_timerType == MZTimerLabelTypeTimer) { 215 | return timeUserValue - [self getTimeCounted]; 216 | } 217 | 218 | return 0; 219 | } 220 | 221 | - (NSTimeInterval)getCountDownTime { 222 | 223 | if (_timerType == MZTimerLabelTypeTimer) { 224 | return timeUserValue; 225 | } 226 | 227 | return 0; 228 | } 229 | 230 | - (void)setShouldCountBeyondHHLimit:(BOOL)shouldCountBeyondHHLimit { 231 | _shouldCountBeyondHHLimit = shouldCountBeyondHHLimit; 232 | [self updateLabel]; 233 | } 234 | 235 | #pragma mark - Timer Control Method 236 | 237 | 238 | -(void)start{ 239 | 240 | if (_timer) { 241 | [_timer invalidate]; 242 | _timer = nil; 243 | } 244 | 245 | if ([self.timeFormat rangeOfString:@"SS"].location != NSNotFound) { 246 | _timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalHighUse target:self selector:@selector(updateLabel) userInfo:nil repeats:YES]; 247 | }else{ 248 | _timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalNormal target:self selector:@selector(updateLabel) userInfo:nil repeats:YES]; 249 | } 250 | [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; 251 | 252 | if(startCountDate == nil){ 253 | startCountDate = [NSDate date]; 254 | 255 | if (self.timerType == MZTimerLabelTypeStopWatch && timeUserValue > 0) { 256 | startCountDate = [startCountDate dateByAddingTimeInterval:-timeUserValue]; 257 | } 258 | } 259 | if(pausedTime != nil){ 260 | NSTimeInterval countedTime = [pausedTime timeIntervalSinceDate:startCountDate]; 261 | startCountDate = [[NSDate date] dateByAddingTimeInterval:-countedTime]; 262 | pausedTime = nil; 263 | } 264 | 265 | _counting = YES; 266 | [_timer fire]; 267 | } 268 | 269 | #if NS_BLOCKS_AVAILABLE 270 | -(void)startWithEndingBlock:(void(^)(NSTimeInterval))end{ 271 | self.endedBlock = end; 272 | [self start]; 273 | } 274 | #endif 275 | 276 | -(void)pause{ 277 | if(_counting){ 278 | [_timer invalidate]; 279 | _timer = nil; 280 | _counting = NO; 281 | pausedTime = [NSDate date]; 282 | } 283 | } 284 | 285 | -(void)reset{ 286 | pausedTime = nil; 287 | timeUserValue = (self.timerType == MZTimerLabelTypeStopWatch)? 0 : timeUserValue; 288 | startCountDate = (self.counting)? [NSDate date] : nil; 289 | [self updateLabel]; 290 | } 291 | 292 | 293 | #pragma mark - Private method 294 | 295 | -(void)setup{ 296 | date1970 = [NSDate dateWithTimeIntervalSince1970:0]; 297 | [self updateLabel]; 298 | } 299 | 300 | 301 | -(void)updateLabel{ 302 | 303 | NSTimeInterval timeDiff = [[NSDate date] timeIntervalSinceDate:startCountDate]; 304 | NSDate *timeToShow = [NSDate date]; 305 | BOOL timerEnded = false; 306 | 307 | /***MZTimerLabelTypeStopWatch Logic***/ 308 | 309 | if(_timerType == MZTimerLabelTypeStopWatch){ 310 | 311 | if (_counting) { 312 | timeToShow = [date1970 dateByAddingTimeInterval:timeDiff]; 313 | }else{ 314 | timeToShow = [date1970 dateByAddingTimeInterval:(!startCountDate)?0:timeDiff]; 315 | } 316 | 317 | if([_delegate respondsToSelector:@selector(timerLabel:countingTo:timertype:)]){ 318 | [_delegate timerLabel:self countingTo:timeDiff timertype:_timerType]; 319 | } 320 | 321 | }else{ 322 | 323 | /***MZTimerLabelTypeTimer Logic***/ 324 | 325 | if (_counting) { 326 | 327 | if([_delegate respondsToSelector:@selector(timerLabel:countingTo:timertype:)]){ 328 | NSTimeInterval timeLeft = timeUserValue - timeDiff; 329 | [_delegate timerLabel:self countingTo:timeLeft timertype:_timerType]; 330 | } 331 | 332 | if(timeDiff >= timeUserValue){ 333 | [self pause]; 334 | timeToShow = [date1970 dateByAddingTimeInterval:0]; 335 | startCountDate = nil; 336 | timerEnded = true; 337 | }else{ 338 | timeToShow = [timeToCountOff dateByAddingTimeInterval:(timeDiff*-1)]; //added 0.999 to make it actually counting the whole first second 339 | } 340 | 341 | }else{ 342 | timeToShow = timeToCountOff; 343 | } 344 | } 345 | 346 | //setting text value 347 | if ([_delegate respondsToSelector:@selector(timerLabel:customTextToDisplayAtTime:)]) { 348 | NSTimeInterval atTime = (_timerType == MZTimerLabelTypeStopWatch) ? timeDiff : ((timeUserValue - timeDiff) < 0 ? 0 : (timeUserValue - timeDiff)); 349 | NSString *customtext = [_delegate timerLabel:self customTextToDisplayAtTime:atTime]; 350 | if ([customtext length]) { 351 | self.timeLabel.text = customtext; 352 | }else{ 353 | self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow]; 354 | } 355 | }else if([_delegate respondsToSelector:@selector(timerLabel:customAttributedTextToDisplayAtTime:)]){ 356 | NSTimeInterval atTime = (_timerType == MZTimerLabelTypeStopWatch) ? timeDiff : ((timeUserValue - timeDiff) < 0 ? 0 : (timeUserValue - timeDiff)); 357 | NSAttributedString *customtext = [_delegate timerLabel:self customAttributedTextToDisplayAtTime:atTime]; 358 | if ([customtext length]) { 359 | self.timeLabel.attributedText = customtext; 360 | }else{ 361 | self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow]; 362 | } 363 | 364 | }else{ 365 | 366 | 367 | if(_shouldCountBeyondHHLimit) { 368 | //0.4.7 added---start// 369 | NSString *originalTimeFormat = _timeFormat; 370 | NSString *beyondFormat = [_timeFormat stringByReplacingOccurrencesOfString:@"HH" withString:kHourFormatReplace]; 371 | beyondFormat = [beyondFormat stringByReplacingOccurrencesOfString:@"H" withString:kHourFormatReplace]; 372 | self.dateFormatter.dateFormat = beyondFormat; 373 | 374 | int hours = (_timerType == MZTimerLabelTypeStopWatch)? ([self getTimeCounted] / 3600) : ([self getTimeRemaining] / 3600); 375 | NSString *formmattedDate = [self.dateFormatter stringFromDate:timeToShow]; 376 | NSString *beyondedDate = [formmattedDate stringByReplacingOccurrencesOfString:kHourFormatReplace withString:[NSString stringWithFormat:@"%02d",hours]]; 377 | 378 | self.timeLabel.text = beyondedDate; 379 | self.dateFormatter.dateFormat = originalTimeFormat; 380 | //0.4.7 added---endb// 381 | }else{ 382 | if(self.textRange.length > 0){ 383 | if(self.attributedDictionaryForTextInRange){ 384 | 385 | NSAttributedString *attrTextInRange = [[NSAttributedString alloc] initWithString:[self.dateFormatter stringFromDate:timeToShow] attributes:self.attributedDictionaryForTextInRange]; 386 | 387 | NSMutableAttributedString *attributedString; 388 | attributedString = [[NSMutableAttributedString alloc]initWithString:self.text]; 389 | [attributedString replaceCharactersInRange:self.textRange withAttributedString:attrTextInRange]; 390 | self.timeLabel.attributedText = attributedString; 391 | 392 | } else { 393 | NSString *labelText = [self.text stringByReplacingCharactersInRange:self.textRange withString:[self.dateFormatter stringFromDate:timeToShow]]; 394 | self.timeLabel.text = labelText; 395 | } 396 | } else { 397 | self.timeLabel.text = [self.dateFormatter stringFromDate:timeToShow]; 398 | } 399 | } 400 | } 401 | 402 | //0.5.1 moved below to the bottom 403 | if(timerEnded) { 404 | if([_delegate respondsToSelector:@selector(timerLabel:finshedCountDownTimerWithTime:)]){ 405 | [_delegate timerLabel:self finshedCountDownTimerWithTime:timeUserValue]; 406 | } 407 | 408 | #if NS_BLOCKS_AVAILABLE 409 | if(_endedBlock != nil){ 410 | _endedBlock(timeUserValue); 411 | } 412 | #endif 413 | if(_resetTimerAfterFinish){ 414 | [self reset]; 415 | } 416 | 417 | } 418 | 419 | } 420 | 421 | @end 422 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3D31ECE7180E7A570085D5D4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D31ECE6180E7A570085D5D4 /* Foundation.framework */; }; 11 | 3D31ECE9180E7A570085D5D4 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D31ECE8180E7A570085D5D4 /* CoreGraphics.framework */; }; 12 | 3D31ECEB180E7A570085D5D4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D31ECEA180E7A570085D5D4 /* UIKit.framework */; }; 13 | 3D31ECF3180E7A570085D5D4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D31ECF2180E7A570085D5D4 /* main.m */; }; 14 | 3D31ECF7180E7A570085D5D4 /* MZTLAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D31ECF6180E7A570085D5D4 /* MZTLAppDelegate.m */; }; 15 | 3D31ECFD180E7A570085D5D4 /* MZTLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D31ECFC180E7A570085D5D4 /* MZTLViewController.m */; }; 16 | 3D31ECFF180E7A570085D5D4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D31ECFE180E7A570085D5D4 /* Images.xcassets */; }; 17 | 3D31ED20180E7C480085D5D4 /* MZTimerLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D31ED1F180E7C480085D5D4 /* MZTimerLabel.m */; }; 18 | 3D31ED26180E8FCA0085D5D4 /* DemoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D31ED25180E8FCA0085D5D4 /* DemoView.xib */; }; 19 | 3D31ED28180E92F80085D5D4 /* MainView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D31ED27180E92F80085D5D4 /* MainView.xib */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 3D31ECE3180E7A570085D5D4 /* MZTimerLabelDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MZTimerLabelDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 3D31ECE6180E7A570085D5D4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 25 | 3D31ECE8180E7A570085D5D4 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 26 | 3D31ECEA180E7A570085D5D4 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 27 | 3D31ECEE180E7A570085D5D4 /* MZTimerLabelDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MZTimerLabelDemo-Info.plist"; sourceTree = ""; }; 28 | 3D31ECF2180E7A570085D5D4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 29 | 3D31ECF4180E7A570085D5D4 /* MZTimerLabelDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MZTimerLabelDemo-Prefix.pch"; sourceTree = ""; }; 30 | 3D31ECF5180E7A570085D5D4 /* MZTLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MZTLAppDelegate.h; sourceTree = ""; }; 31 | 3D31ECF6180E7A570085D5D4 /* MZTLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MZTLAppDelegate.m; sourceTree = ""; }; 32 | 3D31ECFB180E7A570085D5D4 /* MZTLViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MZTLViewController.h; sourceTree = ""; }; 33 | 3D31ECFC180E7A570085D5D4 /* MZTLViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MZTLViewController.m; sourceTree = ""; }; 34 | 3D31ECFE180E7A570085D5D4 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 35 | 3D31ED1E180E7C480085D5D4 /* MZTimerLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MZTimerLabel.h; sourceTree = ""; }; 36 | 3D31ED1F180E7C480085D5D4 /* MZTimerLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MZTimerLabel.m; sourceTree = ""; }; 37 | 3D31ED25180E8FCA0085D5D4 /* DemoView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DemoView.xib; sourceTree = ""; }; 38 | 3D31ED27180E92F80085D5D4 /* MainView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainView.xib; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 3D31ECE0180E7A570085D5D4 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | 3D31ECE9180E7A570085D5D4 /* CoreGraphics.framework in Frameworks */, 47 | 3D31ECEB180E7A570085D5D4 /* UIKit.framework in Frameworks */, 48 | 3D31ECE7180E7A570085D5D4 /* Foundation.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 3D31ECDA180E7A570085D5D4 = { 56 | isa = PBXGroup; 57 | children = ( 58 | 3D31ED1D180E7C480085D5D4 /* MZTimerLabel */, 59 | 3D31ED1B180E7BC20085D5D4 /* Classes */, 60 | 3D31ED1C180E7BD10085D5D4 /* Resources */, 61 | 3D31ECE5180E7A570085D5D4 /* Frameworks */, 62 | 3D31ECE4180E7A570085D5D4 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 3D31ECE4180E7A570085D5D4 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 3D31ECE3180E7A570085D5D4 /* MZTimerLabelDemo.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 3D31ECE5180E7A570085D5D4 /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 3D31ECE6180E7A570085D5D4 /* Foundation.framework */, 78 | 3D31ECE8180E7A570085D5D4 /* CoreGraphics.framework */, 79 | 3D31ECEA180E7A570085D5D4 /* UIKit.framework */, 80 | ); 81 | name = Frameworks; 82 | sourceTree = ""; 83 | }; 84 | 3D31ECED180E7A570085D5D4 /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 3D31ECEE180E7A570085D5D4 /* MZTimerLabelDemo-Info.plist */, 88 | 3D31ECF2180E7A570085D5D4 /* main.m */, 89 | 3D31ECF4180E7A570085D5D4 /* MZTimerLabelDemo-Prefix.pch */, 90 | ); 91 | name = "Supporting Files"; 92 | sourceTree = ""; 93 | }; 94 | 3D31ED1B180E7BC20085D5D4 /* Classes */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 3D31ECF5180E7A570085D5D4 /* MZTLAppDelegate.h */, 98 | 3D31ECF6180E7A570085D5D4 /* MZTLAppDelegate.m */, 99 | 3D31ECFB180E7A570085D5D4 /* MZTLViewController.h */, 100 | 3D31ECFC180E7A570085D5D4 /* MZTLViewController.m */, 101 | ); 102 | name = Classes; 103 | path = MZTimerLabelDemo; 104 | sourceTree = ""; 105 | }; 106 | 3D31ED1C180E7BD10085D5D4 /* Resources */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 3D31ED25180E8FCA0085D5D4 /* DemoView.xib */, 110 | 3D31ED27180E92F80085D5D4 /* MainView.xib */, 111 | 3D31ECFE180E7A570085D5D4 /* Images.xcassets */, 112 | 3D31ECED180E7A570085D5D4 /* Supporting Files */, 113 | ); 114 | name = Resources; 115 | path = MZTimerLabelDemo; 116 | sourceTree = ""; 117 | }; 118 | 3D31ED1D180E7C480085D5D4 /* MZTimerLabel */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 3D31ED1E180E7C480085D5D4 /* MZTimerLabel.h */, 122 | 3D31ED1F180E7C480085D5D4 /* MZTimerLabel.m */, 123 | ); 124 | name = MZTimerLabel; 125 | path = ../MZTimerLabel; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 3D31ECE2180E7A570085D5D4 /* MZTimerLabelDemo */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 3D31ED15180E7A570085D5D4 /* Build configuration list for PBXNativeTarget "MZTimerLabelDemo" */; 134 | buildPhases = ( 135 | 3D31ECDF180E7A570085D5D4 /* Sources */, 136 | 3D31ECE0180E7A570085D5D4 /* Frameworks */, 137 | 3D31ECE1180E7A570085D5D4 /* Resources */, 138 | ); 139 | buildRules = ( 140 | ); 141 | dependencies = ( 142 | ); 143 | name = MZTimerLabelDemo; 144 | productName = MZTimerLabelDemo; 145 | productReference = 3D31ECE3180E7A570085D5D4 /* MZTimerLabelDemo.app */; 146 | productType = "com.apple.product-type.application"; 147 | }; 148 | /* End PBXNativeTarget section */ 149 | 150 | /* Begin PBXProject section */ 151 | 3D31ECDB180E7A570085D5D4 /* Project object */ = { 152 | isa = PBXProject; 153 | attributes = { 154 | CLASSPREFIX = MZTL; 155 | LastUpgradeCheck = 0510; 156 | ORGANIZATIONNAME = "MineS Chan"; 157 | }; 158 | buildConfigurationList = 3D31ECDE180E7A570085D5D4 /* Build configuration list for PBXProject "MZTimerLabelDemo" */; 159 | compatibilityVersion = "Xcode 3.2"; 160 | developmentRegion = English; 161 | hasScannedForEncodings = 0; 162 | knownRegions = ( 163 | en, 164 | Base, 165 | ); 166 | mainGroup = 3D31ECDA180E7A570085D5D4; 167 | productRefGroup = 3D31ECE4180E7A570085D5D4 /* Products */; 168 | projectDirPath = ""; 169 | projectRoot = ""; 170 | targets = ( 171 | 3D31ECE2180E7A570085D5D4 /* MZTimerLabelDemo */, 172 | ); 173 | }; 174 | /* End PBXProject section */ 175 | 176 | /* Begin PBXResourcesBuildPhase section */ 177 | 3D31ECE1180E7A570085D5D4 /* Resources */ = { 178 | isa = PBXResourcesBuildPhase; 179 | buildActionMask = 2147483647; 180 | files = ( 181 | 3D31ED28180E92F80085D5D4 /* MainView.xib in Resources */, 182 | 3D31ECFF180E7A570085D5D4 /* Images.xcassets in Resources */, 183 | 3D31ED26180E8FCA0085D5D4 /* DemoView.xib in Resources */, 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | /* End PBXResourcesBuildPhase section */ 188 | 189 | /* Begin PBXSourcesBuildPhase section */ 190 | 3D31ECDF180E7A570085D5D4 /* Sources */ = { 191 | isa = PBXSourcesBuildPhase; 192 | buildActionMask = 2147483647; 193 | files = ( 194 | 3D31ECF3180E7A570085D5D4 /* main.m in Sources */, 195 | 3D31ED20180E7C480085D5D4 /* MZTimerLabel.m in Sources */, 196 | 3D31ECFD180E7A570085D5D4 /* MZTLViewController.m in Sources */, 197 | 3D31ECF7180E7A570085D5D4 /* MZTLAppDelegate.m in Sources */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | /* End PBXSourcesBuildPhase section */ 202 | 203 | /* Begin XCBuildConfiguration section */ 204 | 3D31ED13180E7A570085D5D4 /* Debug */ = { 205 | isa = XCBuildConfiguration; 206 | buildSettings = { 207 | ALWAYS_SEARCH_USER_PATHS = NO; 208 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 209 | CLANG_CXX_LIBRARY = "libc++"; 210 | CLANG_ENABLE_MODULES = YES; 211 | CLANG_ENABLE_OBJC_ARC = YES; 212 | CLANG_WARN_BOOL_CONVERSION = YES; 213 | CLANG_WARN_CONSTANT_CONVERSION = YES; 214 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 215 | CLANG_WARN_EMPTY_BODY = YES; 216 | CLANG_WARN_ENUM_CONVERSION = YES; 217 | CLANG_WARN_INT_CONVERSION = YES; 218 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 219 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 220 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 221 | COPY_PHASE_STRIP = NO; 222 | GCC_C_LANGUAGE_STANDARD = gnu99; 223 | GCC_DYNAMIC_NO_PIC = NO; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 230 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 231 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 232 | GCC_WARN_UNDECLARED_SELECTOR = YES; 233 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 234 | GCC_WARN_UNUSED_FUNCTION = YES; 235 | GCC_WARN_UNUSED_VARIABLE = YES; 236 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = iphoneos; 239 | }; 240 | name = Debug; 241 | }; 242 | 3D31ED14180E7A570085D5D4 /* Release */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BOOL_CONVERSION = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 258 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 259 | COPY_PHASE_STRIP = YES; 260 | ENABLE_NS_ASSERTIONS = NO; 261 | GCC_C_LANGUAGE_STANDARD = gnu99; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 269 | SDKROOT = iphoneos; 270 | VALIDATE_PRODUCT = YES; 271 | }; 272 | name = Release; 273 | }; 274 | 3D31ED16180E7A570085D5D4 /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 279 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 280 | GCC_PREFIX_HEADER = "MZTimerLabelDemo/MZTimerLabelDemo-Prefix.pch"; 281 | INFOPLIST_FILE = "MZTimerLabelDemo/MZTimerLabelDemo-Info.plist"; 282 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | WRAPPER_EXTENSION = app; 285 | }; 286 | name = Debug; 287 | }; 288 | 3D31ED17180E7A570085D5D4 /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 293 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 294 | GCC_PREFIX_HEADER = "MZTimerLabelDemo/MZTimerLabelDemo-Prefix.pch"; 295 | INFOPLIST_FILE = "MZTimerLabelDemo/MZTimerLabelDemo-Info.plist"; 296 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | WRAPPER_EXTENSION = app; 299 | }; 300 | name = Release; 301 | }; 302 | /* End XCBuildConfiguration section */ 303 | 304 | /* Begin XCConfigurationList section */ 305 | 3D31ECDE180E7A570085D5D4 /* Build configuration list for PBXProject "MZTimerLabelDemo" */ = { 306 | isa = XCConfigurationList; 307 | buildConfigurations = ( 308 | 3D31ED13180E7A570085D5D4 /* Debug */, 309 | 3D31ED14180E7A570085D5D4 /* Release */, 310 | ); 311 | defaultConfigurationIsVisible = 0; 312 | defaultConfigurationName = Release; 313 | }; 314 | 3D31ED15180E7A570085D5D4 /* Build configuration list for PBXNativeTarget "MZTimerLabelDemo" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | 3D31ED16180E7A570085D5D4 /* Debug */, 318 | 3D31ED17180E7A570085D5D4 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | /* End XCConfigurationList section */ 324 | }; 325 | rootObject = 3D31ECDB180E7A570085D5D4 /* Project object */; 326 | } 327 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/DemoView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 97 | 108 | 119 | 130 | 141 | 152 | 163 | 170 | 181 | 188 | 195 | 202 | 213 | 220 | 231 | 242 | 253 | 264 | 275 | 286 | 293 | 300 | 307 | 314 | 321 | 328 | 335 | 342 | 349 | 356 | 363 | 370 | 381 | 388 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/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 | } -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/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 | } -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MZTLAppDelegate.h 3 | // MZTimerLabelDemo 4 | // 5 | // Created by mines.chan on 16/10/13. 6 | // Copyright (c) 2013 MineS Chan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MZTLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) IBOutlet UIWindow *window; 14 | @property (strong, nonatomic) IBOutlet UINavigationController *navController; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MZTLAppDelegate.m 3 | // MZTimerLabelDemo 4 | // 5 | // Created by mines.chan on 16/10/13. 6 | // Copyright (c) 2013 MineS Chan. All rights reserved. 7 | // 8 | 9 | #import "MZTLAppDelegate.h" 10 | #import "MZTLViewController.h" 11 | 12 | @implementation MZTLAppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | _window.rootViewController = _navController; 17 | [_window makeKeyAndVisible]; 18 | return YES; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MZTLViewController.h 3 | // MZTimerLabelDemo 4 | // 5 | // Created by mines.chan on 16/10/13. 6 | // Copyright (c) 2014 MineS Chan. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MZTimerLabel.h" 11 | 12 | @interface MZTLViewController : UIViewController{ 13 | MZTimerLabel *timerExample3; 14 | MZTimerLabel *timerExample4; 15 | MZTimerLabel *timerExample5; 16 | MZTimerLabel *timerExample6; 17 | MZTimerLabel *timerExample7; 18 | MZTimerLabel *timerExample8; 19 | MZTimerLabel *timerExample9; 20 | MZTimerLabel *timerExample10; 21 | MZTimerLabel *timerExample11; 22 | MZTimerLabel *timerExample12; 23 | MZTimerLabel *timerExample13; 24 | } 25 | 26 | /*Controls for Example 1*/ 27 | @property (weak, nonatomic) IBOutlet MZTimerLabel *lblTimerExample1; 28 | 29 | 30 | /*Controls for Example 3*/ 31 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample3; 32 | - (IBAction)getTimerCounted:(id)sender; 33 | - (IBAction)getTimerRemain:(id)sender; 34 | 35 | 36 | /*Controls and Methods for Example 4*/ 37 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample4; 38 | @property (weak, nonatomic) IBOutlet UIButton *btnStartPauseExample4; 39 | - (IBAction)startOrResumeStopwatch:(id)sender; 40 | - (IBAction)resetStopWatch:(id)sender; 41 | 42 | 43 | /*Controls and Methods for Example 5*/ 44 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample5; 45 | @property (weak, nonatomic) IBOutlet UIButton *btnStartPauseExample5; 46 | - (IBAction)startOrResumeCountDown:(id)sender; 47 | - (IBAction)resetCountDown:(id)sender; 48 | 49 | 50 | /*Controls and Methods for Example 6*/ 51 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample6; 52 | @property (weak, nonatomic) IBOutlet UIButton *btnStartCountdownExample6; 53 | - (IBAction)startCountDownWithDelegate:(id)sender; 54 | 55 | 56 | /*Controls and Methods for Example 7*/ 57 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample7; 58 | @property (weak, nonatomic) IBOutlet UIButton *btnStartCountdownExample7; 59 | - (IBAction)startCountDownWithBlock:(id)sender; 60 | 61 | /*Controls and Methods for Example 8*/ 62 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample8; 63 | @property (weak, nonatomic) IBOutlet UIButton *btnStartCountdownExample8; 64 | @property (weak, nonatomic) IBOutlet UIButton *btnAdd2SrcExample8; 65 | - (IBAction)startStopWatchWithProgressDelegate:(id)sender; 66 | 67 | /*Controls and Methods for Example 9*/ 68 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample9; 69 | 70 | /*Controls and Methods for Example 10*/ 71 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample10; 72 | 73 | - (IBAction)add2SecondToCountingStopwatch:(id)sender; 74 | - (IBAction)minus2SecondToCountingStopwatch:(id)sender; 75 | 76 | /*Controls and Methods for Example 11*/ 77 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample11; 78 | - (IBAction)add2SecondToCountingTimer:(id)sender; 79 | - (IBAction)minus2SecondToCountingTimer:(id)sender; 80 | 81 | /*Controls and Methods for Example 12*/ 82 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample12; 83 | - (IBAction)startStopwatchBeyond23Hours:(id)sender; 84 | - (IBAction)toggleStopwatchBeyond24Hours:(id)sender; 85 | 86 | /*Controls and Methods for Example 13*/ 87 | @property (weak, nonatomic) IBOutlet UILabel *lblTimerExample13; 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTLViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MZTLViewController.m 3 | // MZTimerLabelDemo 4 | // 5 | // Created by mines.chan on 16/10/13. 6 | // Copyright (c) 2014 MineS Chan. All rights reserved. 7 | // 8 | 9 | #import "MZTLViewController.h" 10 | #import "MZTimerLabel.h" 11 | 12 | @interface MZTLViewController () 13 | 14 | @end 15 | 16 | @implementation MZTLViewController 17 | 18 | - (void)viewDidLoad 19 | { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | NSArray* demoNib = [[NSBundle mainBundle] loadNibNamed:@"DemoView" owner:self options:nil]; 24 | UIView *demoView = [demoNib lastObject]; 25 | ((UIScrollView *)self.view).contentSize = CGSizeMake(self.view.frame.size.width, demoView.frame.size.height); 26 | 27 | 28 | /******************************************* 29 | * ------Example 1----- 30 | * Use timer on existing and styled MZTimerLabel from Storyboard/Xib, simplest usage. 31 | * REMARKS:initialize without TimerType using MZTimerLabelTypeStopWatch as default 32 | ********************************************/ 33 | [_lblTimerExample1 start]; 34 | 35 | /******************************************* 36 | * ------Example 2----- 37 | * Using MZTimerLabel instance only and set differene time format 38 | ********************************************/ 39 | MZTimerLabel *timer2 = [[MZTimerLabel alloc] initWithFrame:CGRectMake(0, 155, self.view.frame.size.width, 40)]; 40 | timer2.timerType = MZTimerLabelTypeStopWatch; 41 | [self.view addSubview:timer2]; 42 | //do some styling 43 | timer2.timeLabel.backgroundColor = [UIColor clearColor]; 44 | timer2.timeLabel.font = [UIFont systemFontOfSize:28.0f]; 45 | timer2.timeLabel.textColor = [UIColor brownColor]; 46 | timer2.timeLabel.textAlignment = NSTextAlignmentCenter; //UITextAlignmentCenter is deprecated in iOS 7.0 47 | //fire 48 | [timer2 start]; 49 | 50 | 51 | /******************************************* 52 | * ------Example 3----- 53 | * Count Down Timer 54 | ********************************************/ 55 | timerExample3 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample3 andTimerType:MZTimerLabelTypeTimer]; 56 | [timerExample3 setCountDownTime:30*60]; //** Or you can use [timer3 setCountDownToDate:aDate]; 57 | [timerExample3 start]; 58 | 59 | 60 | /******************************************* 61 | * ------Example 4----- 62 | * Stopwatch with controls and time format 63 | * Adjust starting Value 64 | ********************************************/ 65 | timerExample4 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample4 andTimerType:MZTimerLabelTypeStopWatch]; 66 | timerExample4.timeFormat = @"HH:mm:ss SS"; 67 | 68 | 69 | /******************************************* 70 | * ------Example 5----- 71 | * Countdown with controls and time format 72 | ********************************************/ 73 | timerExample5 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample5 andTimerType:MZTimerLabelTypeTimer]; 74 | [timerExample5 setCountDownTime:10]; 75 | 76 | 77 | /******************************************* 78 | * ------Example 6----- 79 | * Countdown finish callback with classic delegate way 80 | * implement - timerLabelEndCountDownTimer:withTime: 81 | ********************************************/ 82 | timerExample6 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample6 andTimerType:MZTimerLabelTypeTimer]; 83 | [timerExample6 setCountDownTime:5]; 84 | timerExample6.resetTimerAfterFinish = YES; 85 | timerExample6.delegate = self; 86 | 87 | /******************************************* 88 | * ------Example 7----- 89 | * Countdown finish callback with convenient callback block 90 | * and showing how to set text of label after. 91 | ********************************************/ 92 | timerExample7 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample7 andTimerType:MZTimerLabelTypeTimer]; 93 | [timerExample7 setCountDownTime:0]; 94 | timerExample7.resetTimerAfterFinish = NO; //IMPORTANT, if you needs custom text with finished, please do not set resetTimerAfterFinish to YES. 95 | timerExample7.timeFormat = @"mm:ss SS"; 96 | 97 | /******************************************* 98 | * ------Example 8----- 99 | * Stopwatch with progress delegate that will change the text to red color if time counted > 10 100 | * Button to add 2 seconds each time you press. 101 | ********************************************/ 102 | timerExample8 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample8]; 103 | timerExample8.timeFormat = @"mm:ss"; 104 | 105 | 106 | /******************************************* 107 | * ------Example 9----- 108 | * Use delegate to determine what text to be shown in corresponding time 109 | * This one display days as addtional hours, see implementation below 110 | ********************************************/ 111 | 112 | timerExample9 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample9 andTimerType:MZTimerLabelTypeTimer]; 113 | [timerExample9 setCountDownTime:3600*24*2]; 114 | timerExample9.delegate = self; 115 | [timerExample9 start]; 116 | 117 | /******************************************* 118 | * ------Example 10----- 119 | * Modify current couting timer of a stopwatch, see implemention below 120 | ********************************************/ 121 | 122 | timerExample10 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample10 andTimerType:MZTimerLabelTypeStopWatch]; 123 | [timerExample10 start]; 124 | 125 | /******************************************* 126 | * ------Example 11----- 127 | * Modify current couting timer of a countdown timer, see implemention below 128 | ********************************************/ 129 | 130 | timerExample11 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample11 andTimerType:MZTimerLabelTypeTimer]; 131 | [timerExample11 setCountDownTime:3600]; 132 | [timerExample11 start]; 133 | 134 | /******************************************* 135 | * ------Example 12----- 136 | * You may need more than 23 hours display in some situation, like if you prefer showing 48 hours rather than 2days. 137 | * As MZTimerLabel uses NSDateFormatter to convert the time difference to String, there is no format string support 138 | * this purpose, so you may implement custom display text demo om example 9. Or set the property `shouldCountBeyondHHLimit` of 139 | * MZTimerLabel. 140 | * REMARKS: Only `HH` and `H` in the format string will be affected. Other hour format like "h", "k", "K" remain their own behaviour. 141 | ********************************************/ 142 | 143 | timerExample12 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample12 andTimerType:MZTimerLabelTypeStopWatch]; 144 | [timerExample12 setStopWatchTime:86395]; 145 | [timerExample12 setShouldCountBeyondHHLimit:YES]; 146 | 147 | /******************************************* 148 | * ------Example 13----- 149 | * Countdown timer in text in custom range 150 | ********************************************/ 151 | 152 | timerExample13 = [[MZTimerLabel alloc] initWithLabel:_lblTimerExample13 andTimerType:MZTimerLabelTypeTimer]; 153 | [timerExample13 setCountDownTime:999]; 154 | NSString* text = @"timer here in text"; 155 | NSRange r = [text rangeOfString:@"here"]; 156 | 157 | UIColor* fgColor = [UIColor redColor]; 158 | NSDictionary* attributesForRange = @{ 159 | NSForegroundColorAttributeName: fgColor, 160 | }; 161 | timerExample13.attributedDictionaryForTextInRange = attributesForRange; 162 | timerExample13.text = text; 163 | timerExample13.textRange = r; 164 | timerExample13.timeFormat = @"ss"; 165 | timerExample13.resetTimerAfterFinish = YES; 166 | [timerExample13 start]; 167 | 168 | } 169 | 170 | /******************************************* 171 | * Method for Example 3 172 | ********************************************/ 173 | 174 | - (IBAction)getTimerCounted:(id)sender { 175 | 176 | NSTimeInterval timeCounted = [timerExample3 getTimeCounted]; 177 | 178 | NSString *msg = [NSString stringWithFormat:@"Timer of Example 3 counted: %f seconds",timeCounted]; 179 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:msg delegate:nil cancelButtonTitle:@"Awesome!" otherButtonTitles:nil]; 180 | [alertView show]; 181 | } 182 | 183 | - (IBAction)getTimerRemain:(id)sender { 184 | 185 | NSTimeInterval timeRemain = [timerExample3 getTimeRemaining]; 186 | 187 | NSString *msg = [NSString stringWithFormat:@"Timer of Example 3 remaining: %f seconds",timeRemain]; 188 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:msg delegate:nil cancelButtonTitle:@"Awesome!" otherButtonTitles:nil]; 189 | [alertView show]; 190 | } 191 | 192 | /******************************************* 193 | * Method for Example 4 194 | ********************************************/ 195 | - (IBAction)startOrResumeStopwatch:(id)sender { 196 | 197 | if([timerExample4 counting]){ 198 | [timerExample4 pause]; 199 | [_btnStartPauseExample4 setTitle:@"Resume" forState:UIControlStateNormal]; 200 | }else{ 201 | [timerExample4 start]; 202 | [_btnStartPauseExample4 setTitle:@"Pause" forState:UIControlStateNormal]; 203 | } 204 | } 205 | 206 | - (IBAction)resetStopWatch:(id)sender { 207 | [timerExample4 reset]; 208 | 209 | if(![timerExample4 counting]){ 210 | [_btnStartPauseExample4 setTitle:@"Start" forState:UIControlStateNormal]; 211 | } 212 | } 213 | 214 | 215 | /******************************************* 216 | * Method for Example 5 217 | ********************************************/ 218 | 219 | - (IBAction)startOrResumeCountDown:(id)sender { 220 | 221 | if([timerExample5 counting]){ 222 | [timerExample5 pause]; 223 | [_btnStartPauseExample5 setTitle:@"Resume" forState:UIControlStateNormal]; 224 | }else{ 225 | [timerExample5 start]; 226 | [_btnStartPauseExample5 setTitle:@"Pause" forState:UIControlStateNormal]; 227 | } 228 | 229 | } 230 | 231 | - (IBAction)resetCountDown:(id)sender { 232 | [timerExample5 reset]; 233 | 234 | if(![timerExample5 counting]){ 235 | [_btnStartPauseExample5 setTitle:@"Start" forState:UIControlStateNormal]; 236 | } 237 | } 238 | 239 | /******************************************* 240 | * Method for Example 6 241 | ********************************************/ 242 | - (IBAction)startCountDownWithDelegate:(id)sender { 243 | 244 | if(![timerExample6 counting]){ 245 | [timerExample6 start]; 246 | } 247 | } 248 | 249 | - (void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime{ 250 | 251 | NSString *msg = [NSString stringWithFormat:@"Countdown of Example 6 finished!\nTime counted: %i seconds",(int)countTime]; 252 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:msg delegate:nil cancelButtonTitle:@"Awesome!" otherButtonTitles:nil]; 253 | [alertView show]; 254 | } 255 | 256 | 257 | /******************************************* 258 | * Method for Example 7 259 | ********************************************/ 260 | - (IBAction)startCountDownWithBlock:(id)sender { 261 | 262 | if(![timerExample7 counting]){ 263 | 264 | [timerExample7 startWithEndingBlock:^(NSTimeInterval countTime) { 265 | timerExample7.timeLabel.text = @"Timer Finished!"; 266 | }]; 267 | 268 | //or you can do this 269 | /* 270 | timerExample7.endedBlock = ^(NSTimeInterval countTime) { 271 | NSString *msg = [NSString stringWithFormat:@"Countdown of Example 7 finished!\nTime counted: %i seconds",(int)countTime]; 272 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:msg delegate:nil cancelButtonTitle:@"Awesome!" otherButtonTitles:nil]; 273 | [alertView show]; 274 | }; 275 | [timerExample7 start]; 276 | */ 277 | } 278 | 279 | } 280 | 281 | /******************************************* 282 | * Method for Example 8 283 | ********************************************/ 284 | 285 | /*****THIS IS MZTimerLabel DELEGATE Method*****/ 286 | - (void)timerLabel:(MZTimerLabel *)timerlabel countingTo:(NSTimeInterval)time timertype:(MZTimerLabelType)timerType{ 287 | 288 | if([timerlabel isEqual:timerExample8] && time > 10){ 289 | timerlabel.timeLabel.textColor = [UIColor redColor]; 290 | } 291 | 292 | } 293 | 294 | - (IBAction)startStopWatchWithProgressDelegate:(id)sender{ 295 | timerExample8.delegate = self; 296 | [timerExample8 start]; 297 | } 298 | 299 | /******************************************* 300 | * Delegate Method for Example 9 301 | ********************************************/ 302 | 303 | /*****THIS IS MZTimerLabel DELEGATE Method*****/ 304 | - (NSString*)timerLabel:(MZTimerLabel *)timerLabel customTextToDisplayAtTime:(NSTimeInterval)time 305 | { 306 | if([timerLabel isEqual:timerExample9]){ 307 | int second = (int)time % 60; 308 | int minute = ((int)time / 60) % 60; 309 | int hours = time / 3600; 310 | return [NSString stringWithFormat:@"%02dh %02dm %02ds",hours,minute,second]; 311 | } 312 | else 313 | return nil; 314 | } 315 | 316 | /******************************************* 317 | * Method for Example 10 318 | ********************************************/ 319 | 320 | - (IBAction)add2SecondToCountingStopwatch:(id)sender { 321 | [timerExample10 addTimeCountedByTime:2]; 322 | } 323 | 324 | - (IBAction)minus2SecondToCountingStopwatch:(id)sender { 325 | [timerExample10 addTimeCountedByTime:-2]; 326 | } 327 | 328 | /******************************************* 329 | * Method for Example 11 330 | ********************************************/ 331 | 332 | - (IBAction)add2SecondToCountingTimer:(id)sender { 333 | [timerExample11 addTimeCountedByTime:2]; 334 | } 335 | 336 | - (IBAction)minus2SecondToCountingTimer:(id)sender { 337 | [timerExample11 addTimeCountedByTime:-2]; 338 | } 339 | 340 | /******************************************* 341 | * Method for Example 12 342 | ********************************************/ 343 | 344 | - (IBAction)startStopwatchBeyond23Hours:(id)sender { 345 | [timerExample12 start]; 346 | } 347 | 348 | - (IBAction)toggleStopwatchBeyond24Hours:(id)sender { 349 | [timerExample12 setShouldCountBeyondHHLimit:!timerExample12.shouldCountBeyondHHLimit]; 350 | } 351 | 352 | @end 353 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTimerLabelDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.mineschan.${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 | NSMainNibFile 28 | MainView 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MZTimerLabelDemo-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 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/MainView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/en.lproj/Main.strings: -------------------------------------------------------------------------------- 1 | 2 | /* Class = "IBUILabel"; text = "00:00:00"; ObjectID = "HCp-zd-MOa"; */ 3 | "HCp-zd-MOa.text" = "00:00:00"; 4 | 5 | /* Class = "IBUILabel"; text = "Using existing UILabel"; ObjectID = "sp8-iP-exa"; */ 6 | "sp8-iP-exa.text" = "Using existing UILabel"; 7 | -------------------------------------------------------------------------------- /MZTimerLabelDemo/MZTimerLabelDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MZTimerLabelDemo 4 | // 5 | // Created by mines.chan on 16/10/13. 6 | // Copyright (c) 2013 MineS Chan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "MZTLAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([MZTLAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MZTimerLabel_Demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mineschan/MZTimerLabel/683531092ca863e36a635824a1bb5f1e6c43a92d/MZTimerLabel_Demo.png -------------------------------------------------------------------------------- /MZTimerLabel_Demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mineschan/MZTimerLabel/683531092ca863e36a635824a1bb5f1e6c43a92d/MZTimerLabel_Demo2.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MZTimerLabel 2 | ============ 3 | 4 | 5 | ![License](https://cocoapod-badges.herokuapp.com/l/MZTimerLabel/badge.(png|svg)) 6 | ![Platforms](https://cocoapod-badges.herokuapp.com/p/MZTimerLabel/badge.png) 7 | [![Cocoapod Latest Version](http://img.shields.io/cocoapods/v/MZTimerLabel.svg?style=flat)](https://cocoapods.org/?q=MZTimerLabel) 8 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 9 | [![Downloads with CocoaPods](https://img.shields.io/cocoapods/dt/MZTimerLabel.svg)](https://cocoapods.org/pods/MZTimerLabel) 10 | 11 | 12 | ScreenShot 13 | ScreenShot2 14 | 15 | ### Purpose 16 | 17 | MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple Clock App with just __2 lines of code__. MZTimerLabel also provides delegate method for you to define the action when the timer finished. 18 | 19 | Author: [MineS Chan](https://github.com/mineschan/) and awesome [contributors](https://github.com/mineschan/MZTimerLabel/graphs/contributors). 20 | 21 | _Remark: This is my first iOS plugin project on github, please accept my apologize if any bad coding._ 22 | 23 | ### Requirements 24 | * ARC 25 | * iOS 5.0+ 26 | 27 | ### Installations 28 | 29 | #### Manual 30 | 31 | 1. Download or clone MZTimerLabel, add `MZTimerLabel.h` and `MZTimerLabel.m` source files into your project. 32 | 2. `#import "MZTimerLabel.h"` whereever you need it. 33 | 34 | #### CocoaPods 35 | 36 | (Unfamiliar with [CocoaPods](http://cocoapods.org/) yet? It's a dependency management tool for iOS and Mac, check it out!) 37 | 38 | ``` 39 | pod 'MZTimerLabel' 40 | ``` 41 | 42 | #### Carthage 43 | Another dependency manager is [Carthage](http://github.com/Carthage/Carthage), which does not have a centralized repository. 44 | 45 | ``` 46 | github "mineschan/MZTimerLabel" 47 | ``` 48 | 49 | ### Easy Example 50 | 51 | To use MZTimerLabel as a stopwatch and counter, you need only __2 lines__. 52 | ```objective-c 53 | MZTimerLabel *stopwatch = [[MZTimerLabel alloc] initWithLabel:aUILabel]; 54 | [stopwatch start]; 55 | ``` 56 | 57 | Easy? If you are looking for a timer, things is just similar. 58 | ```objective-c 59 | MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer]; 60 | [timer setCountDownTime:60]; 61 | [timer start]; 62 | ``` 63 | 64 | Now the timer will start counting from 60 to 0 ;) 65 | 66 | ### Custom Appearance 67 | 68 | As MZTimerLabel is a UILabel subclass, you can directly allocate it as a normal UILabel and customize `timeLabel` property just like usual. 69 | 70 | ```objective-c 71 | MZTimerLabel *redStopwatch = [[MZTimerLabel alloc] init]; 72 | redStopwatch.frame = CGRectMake(100,50,100,20); 73 | redStopwatch.timeLabel.font = [UIFont systemFontOfSize:20.0f]; 74 | redStopwatch.timeLabel.textColor = [UIColor redColor]; 75 | [self.view addSubview:redStopwatch]; 76 | [redStopwatch start]; 77 | ``` 78 | 79 | MZTimerLabel uses `00:00:00 (HH:mm:ss)` as time format, if you prefer using another format such as including milliseconds.Your can set your time format like below. 80 | 81 | `timerExample4.timeFormat = @"HH:mm:ss SS";` 82 | 83 | 84 | 85 | ### Control the timer 86 | 87 | You can start,pause,reset your timer with your custom control, set your control up and call these methods: 88 | 89 | ``` 90 | -(void)start; 91 | -(void)pause; 92 | -(void)reset; 93 | ``` 94 | 95 | #### Getter and Setters 96 | 97 | You may control the time value and behaviours at the begining or during runtime with these properties and methods 98 | 99 | ``` 100 | @property (assign) BOOL shouldCountBeyondHHLimit; //see example #12 101 | @property (assign) BOOL resetTimerAfterFinish; //see example #7 102 | 103 | -(void)setCountDownTime:(NSTimeInterval)time; 104 | -(void)setStopWatchTime:(NSTimeInterval)time; 105 | -(void)setCountDownToDate:(NSDate*)date; 106 | -(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd; //see example #10, #11 107 | ``` 108 | 109 | And if you want to have information of the timer, here is how. 110 | 111 | ``` 112 | @property (assign,readonly) BOOL counting; //see example #4-7 113 | 114 | - (NSTimeInterval)getTimeCounted; //see example #3 115 | - (NSTimeInterval)getTimeRemaining; //see example #3 116 | - (NSTimeInterval)getCountDownTime; 117 | ``` 118 | 119 | ### Timer Finish Handling 120 | 121 | Usually when you need a timer, you need to deal with it after it finished. Following are 2 examples showing how to do it using `delegate` and `block` methods. 122 | 123 | #### Delegate 124 | 125 | First, set the delegate of the timer label. 126 | 127 | `timer.delegate = self;` 128 | 129 | And then implement `MZTimerLabelDelegate` protocol in your dedicated class 130 | 131 | `@interface ViewController : UIViewController` 132 | 133 | Finally, implement the delegate method `timerLabel:finshedCountDownTimerWithTimeWithTime:` 134 | 135 | ```objective-c 136 | -(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime{ 137 | //time is up, what should I do master? 138 | } 139 | ``` 140 | 141 | #### Blocks 142 | 143 | Block is a very convenient way to handle the callbacks, MZTimerLabel makes your life even easier. 144 | 145 | ```objective-c 146 | 147 | MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer]; 148 | [timer3 setCountDownTime:60]; 149 | [timer startWithEndingBlock:^(NSTimeInterval countTime) { 150 | //oh my gosh, it's awesome!! 151 | }]; 152 | 153 | ``` 154 | 155 | Or set it seperately 156 | 157 | ``` 158 | [timer3 setCountDownTime:60]; 159 | timer.endedBlock = ^(NSTimeInterval countTime) { 160 | //oh my gosh, it's awesome!! 161 | }; 162 | [timer start]; 163 | ``` 164 | 165 | 166 | ### More Examples 167 | 168 | Please check the demo project I provided, with well explained example code inside. 169 | 170 | ### License 171 | This code is distributed under the terms and conditions of the [MIT license](LICENSE). 172 | 173 | 174 | ### What's coming up next? 175 | 176 | 1. ~~Submit to CocaPods~~ 177 | 2. ~~Better performance.~~ 178 | 3. __Your suggestions!:D__ 179 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mineschan/MZTimerLabel/683531092ca863e36a635824a1bb5f1e6c43a92d/demo.gif --------------------------------------------------------------------------------