diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2cf36d5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 jkpang + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PPCounter.gif b/PPCounter.gif new file mode 100644 index 0000000..504068f Binary files /dev/null and b/PPCounter.gif differ diff --git a/PPCounter.podspec b/PPCounter.podspec new file mode 100755 index 0000000..fdd3571 --- /dev/null +++ b/PPCounter.podspec @@ -0,0 +1,22 @@ + +Pod::Spec.new do |s| + + s.name = "PPCounter" + s.version = "0.1.0" + s.summary = "一款简单实用的数字加减动画,支持UILabel、UIButton显示" + + s.homepage = "https://github.com/jkpang/PPCounter.git" + + s.license = { :type => "MIT", :file => "LICENSE" } + + s.author = { "jkpang" => "jkpang@outlook.com" } + + s.platform = :ios, "7.0" + + s.source = { :git => "https://github.com/jkpang/PPCounter.git", :tag => s.version.to_s } + + s.source_files = "PPCounter/PPCounter/*.{h,m}" + + s.requires_arc = true + +end diff --git a/PPCounter.xcodeproj/project.pbxproj b/PPCounter.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f4a2354 --- /dev/null +++ b/PPCounter.xcodeproj/project.pbxproj @@ -0,0 +1,463 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 226FB26F1DB2568D000BE4F3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB26E1DB2568D000BE4F3 /* main.m */; }; + 226FB2721DB2568D000BE4F3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB2711DB2568D000BE4F3 /* AppDelegate.m */; }; + 226FB2751DB2568D000BE4F3 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB2741DB2568D000BE4F3 /* ViewController.m */; }; + 226FB2781DB2568D000BE4F3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 226FB2761DB2568D000BE4F3 /* Main.storyboard */; }; + 226FB27A1DB2568D000BE4F3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 226FB2791DB2568D000BE4F3 /* Assets.xcassets */; }; + 226FB27D1DB2568D000BE4F3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 226FB27B1DB2568D000BE4F3 /* LaunchScreen.storyboard */; }; + 226FB2881DB2568D000BE4F3 /* PPCounterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB2871DB2568D000BE4F3 /* PPCounterTests.m */; }; + 226FB2951DB256CC000BE4F3 /* PPCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB2941DB256CC000BE4F3 /* PPCounter.m */; }; + 226FB2981DB257E5000BE4F3 /* UILabel+PPCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = 226FB2971DB257E5000BE4F3 /* UILabel+PPCounter.m */; }; + 22E75AD61DB51F950046E7D8 /* UIButton+PPCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E75AD51DB51F950046E7D8 /* UIButton+PPCounter.m */; }; + 22E75AD91DB520C80046E7D8 /* PPCounterConst.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E75AD81DB520C80046E7D8 /* PPCounterConst.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 226FB2841DB2568D000BE4F3 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 226FB2621DB2568D000BE4F3 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 226FB2691DB2568D000BE4F3; + remoteInfo = PPCounter; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 226FB26A1DB2568D000BE4F3 /* PPCounter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PPCounter.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 226FB26E1DB2568D000BE4F3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 226FB2701DB2568D000BE4F3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 226FB2711DB2568D000BE4F3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 226FB2731DB2568D000BE4F3 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 226FB2741DB2568D000BE4F3 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 226FB2771DB2568D000BE4F3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 226FB2791DB2568D000BE4F3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 226FB27C1DB2568D000BE4F3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 226FB27E1DB2568D000BE4F3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 226FB2831DB2568D000BE4F3 /* PPCounterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PPCounterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 226FB2871DB2568D000BE4F3 /* PPCounterTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PPCounterTests.m; sourceTree = ""; }; + 226FB2891DB2568D000BE4F3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 226FB2931DB256CC000BE4F3 /* PPCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPCounter.h; sourceTree = ""; }; + 226FB2941DB256CC000BE4F3 /* PPCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPCounter.m; sourceTree = ""; }; + 226FB2961DB257E5000BE4F3 /* UILabel+PPCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+PPCounter.h"; sourceTree = ""; }; + 226FB2971DB257E5000BE4F3 /* UILabel+PPCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+PPCounter.m"; sourceTree = ""; }; + 22E75AD41DB51F950046E7D8 /* UIButton+PPCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+PPCounter.h"; sourceTree = ""; }; + 22E75AD51DB51F950046E7D8 /* UIButton+PPCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+PPCounter.m"; sourceTree = ""; }; + 22E75AD71DB520C80046E7D8 /* PPCounterConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPCounterConst.h; sourceTree = ""; }; + 22E75AD81DB520C80046E7D8 /* PPCounterConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPCounterConst.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 226FB2671DB2568D000BE4F3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 226FB2801DB2568D000BE4F3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 226FB2611DB2568D000BE4F3 = { + isa = PBXGroup; + children = ( + 226FB26C1DB2568D000BE4F3 /* PPCounter */, + 226FB2861DB2568D000BE4F3 /* PPCounterTests */, + 226FB26B1DB2568D000BE4F3 /* Products */, + ); + sourceTree = ""; + }; + 226FB26B1DB2568D000BE4F3 /* Products */ = { + isa = PBXGroup; + children = ( + 226FB26A1DB2568D000BE4F3 /* PPCounter.app */, + 226FB2831DB2568D000BE4F3 /* PPCounterTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 226FB26C1DB2568D000BE4F3 /* PPCounter */ = { + isa = PBXGroup; + children = ( + 226FB2921DB256AB000BE4F3 /* PPCounter */, + 226FB2701DB2568D000BE4F3 /* AppDelegate.h */, + 226FB2711DB2568D000BE4F3 /* AppDelegate.m */, + 226FB2731DB2568D000BE4F3 /* ViewController.h */, + 226FB2741DB2568D000BE4F3 /* ViewController.m */, + 226FB2761DB2568D000BE4F3 /* Main.storyboard */, + 226FB2791DB2568D000BE4F3 /* Assets.xcassets */, + 226FB27B1DB2568D000BE4F3 /* LaunchScreen.storyboard */, + 226FB27E1DB2568D000BE4F3 /* Info.plist */, + 226FB26D1DB2568D000BE4F3 /* Supporting Files */, + ); + path = PPCounter; + sourceTree = ""; + }; + 226FB26D1DB2568D000BE4F3 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 226FB26E1DB2568D000BE4F3 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 226FB2861DB2568D000BE4F3 /* PPCounterTests */ = { + isa = PBXGroup; + children = ( + 226FB2871DB2568D000BE4F3 /* PPCounterTests.m */, + 226FB2891DB2568D000BE4F3 /* Info.plist */, + ); + path = PPCounterTests; + sourceTree = ""; + }; + 226FB2921DB256AB000BE4F3 /* PPCounter */ = { + isa = PBXGroup; + children = ( + 226FB2931DB256CC000BE4F3 /* PPCounter.h */, + 226FB2941DB256CC000BE4F3 /* PPCounter.m */, + 22E75AD71DB520C80046E7D8 /* PPCounterConst.h */, + 22E75AD81DB520C80046E7D8 /* PPCounterConst.m */, + 226FB2961DB257E5000BE4F3 /* UILabel+PPCounter.h */, + 226FB2971DB257E5000BE4F3 /* UILabel+PPCounter.m */, + 22E75AD41DB51F950046E7D8 /* UIButton+PPCounter.h */, + 22E75AD51DB51F950046E7D8 /* UIButton+PPCounter.m */, + ); + path = PPCounter; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 226FB2691DB2568D000BE4F3 /* PPCounter */ = { + isa = PBXNativeTarget; + buildConfigurationList = 226FB28C1DB2568D000BE4F3 /* Build configuration list for PBXNativeTarget "PPCounter" */; + buildPhases = ( + 226FB2661DB2568D000BE4F3 /* Sources */, + 226FB2671DB2568D000BE4F3 /* Frameworks */, + 226FB2681DB2568D000BE4F3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PPCounter; + productName = PPCounter; + productReference = 226FB26A1DB2568D000BE4F3 /* PPCounter.app */; + productType = "com.apple.product-type.application"; + }; + 226FB2821DB2568D000BE4F3 /* PPCounterTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 226FB28F1DB2568D000BE4F3 /* Build configuration list for PBXNativeTarget "PPCounterTests" */; + buildPhases = ( + 226FB27F1DB2568D000BE4F3 /* Sources */, + 226FB2801DB2568D000BE4F3 /* Frameworks */, + 226FB2811DB2568D000BE4F3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 226FB2851DB2568D000BE4F3 /* PBXTargetDependency */, + ); + name = PPCounterTests; + productName = PPCounterTests; + productReference = 226FB2831DB2568D000BE4F3 /* PPCounterTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 226FB2621DB2568D000BE4F3 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0800; + ORGANIZATIONNAME = AndyPang; + TargetAttributes = { + 226FB2691DB2568D000BE4F3 = { + CreatedOnToolsVersion = 8.0; + ProvisioningStyle = Automatic; + }; + 226FB2821DB2568D000BE4F3 = { + CreatedOnToolsVersion = 8.0; + ProvisioningStyle = Automatic; + TestTargetID = 226FB2691DB2568D000BE4F3; + }; + }; + }; + buildConfigurationList = 226FB2651DB2568D000BE4F3 /* Build configuration list for PBXProject "PPCounter" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 226FB2611DB2568D000BE4F3; + productRefGroup = 226FB26B1DB2568D000BE4F3 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 226FB2691DB2568D000BE4F3 /* PPCounter */, + 226FB2821DB2568D000BE4F3 /* PPCounterTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 226FB2681DB2568D000BE4F3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 226FB27D1DB2568D000BE4F3 /* LaunchScreen.storyboard in Resources */, + 226FB27A1DB2568D000BE4F3 /* Assets.xcassets in Resources */, + 226FB2781DB2568D000BE4F3 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 226FB2811DB2568D000BE4F3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 226FB2661DB2568D000BE4F3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 22E75AD61DB51F950046E7D8 /* UIButton+PPCounter.m in Sources */, + 226FB2751DB2568D000BE4F3 /* ViewController.m in Sources */, + 226FB2721DB2568D000BE4F3 /* AppDelegate.m in Sources */, + 226FB2951DB256CC000BE4F3 /* PPCounter.m in Sources */, + 226FB26F1DB2568D000BE4F3 /* main.m in Sources */, + 22E75AD91DB520C80046E7D8 /* PPCounterConst.m in Sources */, + 226FB2981DB257E5000BE4F3 /* UILabel+PPCounter.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 226FB27F1DB2568D000BE4F3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 226FB2881DB2568D000BE4F3 /* PPCounterTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 226FB2851DB2568D000BE4F3 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 226FB2691DB2568D000BE4F3 /* PPCounter */; + targetProxy = 226FB2841DB2568D000BE4F3 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 226FB2761DB2568D000BE4F3 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 226FB2771DB2568D000BE4F3 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 226FB27B1DB2568D000BE4F3 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 226FB27C1DB2568D000BE4F3 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 226FB28A1DB2568D000BE4F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 226FB28B1DB2568D000BE4F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 226FB28D1DB2568D000BE4F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = PPCounter/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.jkpang.PPCounter; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 226FB28E1DB2568D000BE4F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = PPCounter/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.jkpang.PPCounter; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 226FB2901DB2568D000BE4F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + INFOPLIST_FILE = PPCounterTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.jkpang.PPCounterTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PPCounter.app/PPCounter"; + }; + name = Debug; + }; + 226FB2911DB2568D000BE4F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + INFOPLIST_FILE = PPCounterTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.jkpang.PPCounterTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PPCounter.app/PPCounter"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 226FB2651DB2568D000BE4F3 /* Build configuration list for PBXProject "PPCounter" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 226FB28A1DB2568D000BE4F3 /* Debug */, + 226FB28B1DB2568D000BE4F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 226FB28C1DB2568D000BE4F3 /* Build configuration list for PBXNativeTarget "PPCounter" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 226FB28D1DB2568D000BE4F3 /* Debug */, + 226FB28E1DB2568D000BE4F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 226FB28F1DB2568D000BE4F3 /* Build configuration list for PBXNativeTarget "PPCounterTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 226FB2901DB2568D000BE4F3 /* Debug */, + 226FB2911DB2568D000BE4F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 226FB2621DB2568D000BE4F3 /* Project object */; +} diff --git a/PPCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PPCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..7d20595 --- /dev/null +++ b/PPCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/AndyPang.xcuserdatad/UserInterfaceState.xcuserstate b/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/AndyPang.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..d3920cc Binary files /dev/null and b/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/AndyPang.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/duoyi.xcuserdatad/UserInterfaceState.xcuserstate b/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/duoyi.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..920691f Binary files /dev/null and b/PPCounter.xcodeproj/project.xcworkspace/xcuserdata/duoyi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..8f94031 --- /dev/null +++ b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/PPCounter.xcscheme b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/PPCounter.xcscheme new file mode 100644 index 0000000..9e9dbef --- /dev/null +++ b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/PPCounter.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/xcschememanagement.plist b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..7a278ed --- /dev/null +++ b/PPCounter.xcodeproj/xcuserdata/AndyPang.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + PPCounter.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 226FB2691DB2568D000BE4F3 + + primary + + + 226FB2821DB2568D000BE4F3 + + primary + + + + + diff --git a/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/PPCounter.xcscheme b/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/PPCounter.xcscheme new file mode 100644 index 0000000..9e9dbef --- /dev/null +++ b/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/PPCounter.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/xcschememanagement.plist b/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..7a278ed --- /dev/null +++ b/PPCounter.xcodeproj/xcuserdata/duoyi.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + PPCounter.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 226FB2691DB2568D000BE4F3 + + primary + + + 226FB2821DB2568D000BE4F3 + + primary + + + + + diff --git a/PPCounter/AppDelegate.h b/PPCounter/AppDelegate.h new file mode 100644 index 0000000..f9f5290 --- /dev/null +++ b/PPCounter/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/PPCounter/AppDelegate.m b/PPCounter/AppDelegate.m new file mode 100644 index 0000000..269d1fc --- /dev/null +++ b/PPCounter/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // 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. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // 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. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // 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. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/PPCounter/Assets.xcassets/AppIcon.appiconset/Contents.json b/PPCounter/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/PPCounter/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/PPCounter/Base.lproj/LaunchScreen.storyboard b/PPCounter/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/PPCounter/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PPCounter/Base.lproj/Main.storyboard b/PPCounter/Base.lproj/Main.storyboard new file mode 100644 index 0000000..ee6e091 --- /dev/null +++ b/PPCounter/Base.lproj/Main.storyboard @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PPCounter/Info.plist b/PPCounter/Info.plist new file mode 100644 index 0000000..d052473 --- /dev/null +++ b/PPCounter/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/PPCounter/PPCounter/PPCounter.h b/PPCounter/PPCounter/PPCounter.h new file mode 100644 index 0000000..cb1c2b6 --- /dev/null +++ b/PPCounter/PPCounter/PPCounter.h @@ -0,0 +1,31 @@ +// +// PPCounter.h +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import "PPCounterConst.h" + +@interface PPCounter : NSObject + +/** + 类方法创建一个计数器的实例 + */ ++ (instancetype)counter; + +/** + 在指定时间内数字从 numberA -> numberB + + @param starNumer 开始的数字 + @param endNumber 结束的数字 + @param duration 指定的时间 + @param animationType 动画类型 + @param numberBlock 当前数字的回调 + @param completionBlock 已完成的回调 + */ +- (void)fromNumber:(CGFloat)starNumer toNumber:(CGFloat)endNumber duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType currentNumber:(PPCurrentNumberBlock)numberBlock complete:(PPCompletionBlock)completionBlock; + +@end diff --git a/PPCounter/PPCounter/PPCounter.m b/PPCounter/PPCounter/PPCounter.m new file mode 100644 index 0000000..dccd8b5 --- /dev/null +++ b/PPCounter/PPCounter/PPCounter.m @@ -0,0 +1,176 @@ +// +// PPCounter.m +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import "PPCounter.h" + +/** 函数指针*/ +typedef CGFloat (*PPCurrentBufferFunction)(CGFloat); + + +@interface PPCounter () +/** 定时器*/ +@property (nonatomic, strong) CADisplayLink *timer; +/** 开始的数字*/ +@property (nonatomic, assign) CGFloat starNumber; +/** 结束的数字*/ +@property (nonatomic, assign) CGFloat endNumber; + +/** 动画的总持续时间*/ +@property (nonatomic, assign) CFTimeInterval durationTime; +/** 记录上一帧动画的时间*/ +@property (nonatomic, assign) CFTimeInterval lastTime; +/** 记录动画已持续的时间*/ +@property (nonatomic, assign) CFTimeInterval progressTime; + +/** 获取当前数字的Block*/ +@property (nonatomic, copy) PPCurrentNumberBlock numberBlock; +/** 计数完成的Block*/ +@property (nonatomic, copy) PPCompletionBlock completionBlock; + +/** 动画函数*/ +@property PPCurrentBufferFunction currentBufferFunction; + +@end + +@implementation PPCounter + +- (instancetype)init +{ + if (self = [super init]) + { + _currentBufferFunction = PPBufferFunctionEaseOut; + } + return self; +} + ++ (instancetype)counter +{ + return [[self alloc] init]; +} + +- (void)fromNumber:(CGFloat)starNumer toNumber:(CGFloat)endNumber duration:(CFTimeInterval)durationTime animationType:(PPCounterAnimationType)animationType currentNumber:(PPCurrentNumberBlock)numberBlock complete:(PPCompletionBlock)completionBlock +{ + // 开始前清空定时器 + [self cleanTimer]; + + // 初始化相关变量 + _starNumber = starNumer; + _endNumber = endNumber; + _durationTime = durationTime; + + // 设置缓冲动画类型 + [self setAnimationType:animationType]; + + // 设置block回调函数 + numberBlock ? _numberBlock = numberBlock : nil ; + completionBlock ? _completionBlock = completionBlock : nil ; + + // 记录定时器运行前的时间 + _lastTime = CACurrentMediaTime(); + + // 实例化定时器 + _timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(changeNumber)]; + _timer.frameInterval = 2; + [_timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; + [_timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode]; + +} + +- (void)changeNumber +{ + // 1.记录当前动画开始的时间 + CFTimeInterval thisTime = CACurrentMediaTime(); + // 2.计算动画已持续的时间量 + _progressTime = _progressTime + (thisTime - _lastTime); + // 3.准备下一次的计算 + _lastTime = thisTime; + + if (_progressTime >= _durationTime) + { + [self cleanTimer]; + _numberBlock ? _numberBlock(_endNumber) : nil ; + _completionBlock ? _completionBlock() : nil ; + return; + } + _numberBlock ? _numberBlock([self computeNumber]) : nil ; + +} + +- (void)setAnimationType:(PPCounterAnimationType)animationType +{ + switch (animationType) + { + case PPCounterAnimationTypeEaseOut: + _currentBufferFunction = PPBufferFunctionEaseOut; + break; + case PPCounterAnimationTypeEaseIn: + _currentBufferFunction = PPBufferFunctionEaseIn; + break; + case PPCounterAnimationTypeEaseInOut: + _currentBufferFunction = PPBufferFunctionEaseInOut; + break; + case PPCounterAnimationTypeLinear: + _currentBufferFunction = PPBufferFunctionLinear; + break; + default: + break; + } +} + +/** + 计算数字 + */ +- (CGFloat)computeNumber +{ + CGFloat percent = _progressTime / _durationTime; + return _starNumber + (_currentBufferFunction(percent) * (_endNumber - _starNumber)); +} + +/** + 清除定时器 + */ +- (void)cleanTimer +{ + [_timer invalidate]; + _timer = nil; + _progressTime = 0; +} + +#pragma mark - 缓冲动画函数 + +CGFloat PPBufferFunctionEaseOut(CGFloat p) +{ + return (p == 1.0) ? p : 1 - pow(2, -10 * p); +} + +CGFloat PPBufferFunctionEaseIn(CGFloat p) +{ + return (p == 0.0) ? p : pow(2, 10 * (p - 1)); +} + +CGFloat PPBufferFunctionEaseInOut(CGFloat p) +{ + if(p == 0.0 || p == 1.0) return p; + + if(p < 0.5) + { + return 0.5 * pow(2, (20 * p) - 10); + } + else + { + return -0.5 * pow(2, (-20 * p) + 10) + 1; + } +} + +CGFloat PPBufferFunctionLinear(CGFloat p) +{ + return p; +} + +@end diff --git a/PPCounter/PPCounter/PPCounterConst.h b/PPCounter/PPCounter/PPCounterConst.h new file mode 100644 index 0000000..291a9c8 --- /dev/null +++ b/PPCounter/PPCounter/PPCounterConst.h @@ -0,0 +1,31 @@ +// +// PPCounterConst.h +// PPCounter +// +// Created by AndyPang on 16/10/17. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import + +UIKIT_EXTERN NSString *const kPPCounterAnimationType; + +typedef void(^PPCompletionBlock)(void); + +typedef void(^PPCurrentNumberBlock)(CGFloat number); + +typedef NSString *(^PPFormatBlock)(CGFloat number); + +typedef NSAttributedString *(^PPAttributedFormatBlock)(CGFloat number); + +typedef NS_ENUM(NSUInteger, PPCounterAnimationType) { + /** 由快到慢*/ + PPCounterAnimationTypeEaseOut = 1, + /** 由慢到快*/ + PPCounterAnimationTypeEaseIn, + /** 由慢到快,再由快到慢*/ + PPCounterAnimationTypeEaseInOut, + /** 匀速*/ + PPCounterAnimationTypeLinear +}; diff --git a/PPCounter/PPCounter/PPCounterConst.m b/PPCounter/PPCounter/PPCounterConst.m new file mode 100644 index 0000000..0ca3d67 --- /dev/null +++ b/PPCounter/PPCounter/PPCounterConst.m @@ -0,0 +1,11 @@ +// +// PPCounterConst.m +// PPCounter +// +// Created by AndyPang on 16/10/17. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import "PPCounterConst.h" + +NSString *const kPPCounterAnimationType = @"kPPCounterAnimationType"; diff --git a/PPCounter/PPCounter/UIButton+PPCounter.h b/PPCounter/PPCounter/UIButton+PPCounter.h new file mode 100644 index 0000000..df3ecbe --- /dev/null +++ b/PPCounter/PPCounter/UIButton+PPCounter.h @@ -0,0 +1,101 @@ +// +// UIButton+PPCounter.h +// PPCounter +// +// Created by AndyPang on 16/10/17. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import "PPCounter.h" + +@interface UIButton (PPCounter) + +/** 动画类型*/ +@property (nonatomic, assign) PPCounterAnimationType counterAnimationType; + +/** + 在1.5s内,一般字体属性UIButton中的数字从 0 -> number + + @param number 结束的数字 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromZeroToNumber:(CGFloat)number formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在1.5s内,富文本字体属性UIButton中的数字从 0 -> number + + @param number 结束的数字 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromZeroToNumber:(CGFloat)number attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + +/** + 在1.5s内,一般字体属性UIButton中的数字从 numberA -> numberB + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在1.5s内,富文本字体属性UIButton中的数字从 numberA -> numberB + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + +/** + 在指定时间内,一般字体属性UIButton中的数字从 numberA -> numberB, + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在指定时间内,富文本字体属性UIButton中的数字从 numberA -> numberB, + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + +/** + 在指定时间内,一般字体属性UIButton中的数字从 numberA -> numberB, + 可设置动画类型 + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param animationType 动画类型 + @param formatBlock 设置字体一般属性的block + @param completionBlock 完成的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType formatBlock:(PPFormatBlock)formatBlock completeBlock:(PPCompletionBlock)completionBlock; + +/** + 在指定时间内,富文本字体属性UIButton中的数字从 numberA -> numberB, + 可设置动画类型 + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param animationType 动画类型 + @param attributedFormatBlock 设置富文本字体属性的Block + @param completionBlock 完成的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock completeBlock:(PPCompletionBlock)completionBlock; + + +@end diff --git a/PPCounter/PPCounter/UIButton+PPCounter.m b/PPCounter/PPCounter/UIButton+PPCounter.m new file mode 100644 index 0000000..31664d3 --- /dev/null +++ b/PPCounter/PPCounter/UIButton+PPCounter.m @@ -0,0 +1,83 @@ +// +// UIButton+PPCounter.m +// PPCounter +// +// Created by AndyPang on 16/10/17. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import "UIButton+PPCounter.h" +#import + +@implementation UIButton (PPCounter) + +- (void)pp_fromZeroToNumber:(CGFloat)number formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:0.f toNumber:number duration:1.5f animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromZeroToNumber:(CGFloat)number attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:0.f toNumber:number duration:1.5f animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:1.5f animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:1.5f animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:duration animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:duration animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +#pragma mark - normal font +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType formatBlock:(PPFormatBlock)formatBlock completeBlock:(PPCompletionBlock)completionBlock +{ + + [[PPCounter counter] fromNumber:numberA toNumber:numberB duration:duration animationType:animationType currentNumber:^(CGFloat number) { + + formatBlock ? [self setTitle:formatBlock(number) forState:UIControlStateNormal] : nil ; + + } complete:completionBlock]; + +} + +#pragma mark - attributed font +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock completeBlock:(PPCompletionBlock)completionBlock +{ + [[PPCounter counter] fromNumber:numberA toNumber:numberB duration:duration animationType:animationType currentNumber:^(CGFloat number) { + + attributedFormatBlock ? [self setAttributedTitle:attributedFormatBlock(number) forState:UIControlStateNormal] : nil ; + + } complete:completionBlock]; +} + +#pragma mark - setter/getter + +- (void)setCounterAnimationType:(PPCounterAnimationType)counterAnimationType +{ + objc_setAssociatedObject(self, &kPPCounterAnimationType, @(counterAnimationType), OBJC_ASSOCIATION_ASSIGN); +} + +- (PPCounterAnimationType)counterAnimationType +{ + return [objc_getAssociatedObject(self, &kPPCounterAnimationType) integerValue]; +} +@end diff --git a/PPCounter/PPCounter/UILabel+PPCounter.h b/PPCounter/PPCounter/UILabel+PPCounter.h new file mode 100644 index 0000000..48fadbd --- /dev/null +++ b/PPCounter/PPCounter/UILabel+PPCounter.h @@ -0,0 +1,103 @@ +// +// UILabel+PPCounter.h +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import "PPCounter.h" + +@class PPCounter; + +@interface UILabel (PPCounter) + +/** 动画类型*/ +@property (nonatomic, assign) PPCounterAnimationType counterAnimationType; + +/** + 在1.5s内,一般字体属性UILabel中的数字从 0 -> number + + @param number 结束的数字 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromZeroToNumber:(CGFloat)number formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在1.5s内,富文本字体属性UILabel中的数字从 0 -> number + + @param number 结束的数字 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromZeroToNumber:(CGFloat)number attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + + +/** + 在1.5s内,一般字体属性UILabel中的数字从 numberA -> numberB + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在1.5s内,富文本字体属性UILabel中的数字从 numberA -> numberB + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + +/** + 在指定时间内,一般字体属性UILabel中的数字从 numberA -> numberB, + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param formatBlock 设置字体一般属性的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration formatBlock:(PPFormatBlock)formatBlock; + + +/** + 在指定时间内,富文本字体属性UILabel中的数字从 numberA -> numberB, + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param attributedFormatBlock 设置富文本字体属性的Block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock; + +/** + 在指定时间内,一般字体属性UILabel中的数字从 numberA -> numberB, + 可设置动画类型 + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param animationType 动画类型 + @param formatBlock 设置字体一般属性的block + @param completionBlock 完成的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType formatBlock:(PPFormatBlock)formatBlock completeBlock:(PPCompletionBlock)completionBlock; + +/** + 在指定时间内,富文本字体属性UILabel中的数字从 numberA -> numberB, + 可设置动画类型 + + @param numberA 开始的数字 + @param numberB 结束的数字 + @param duration 持续时间 + @param animationType 动画类型 + @param attributedFormatBlock 设置富文本字体属性的Block + @param completionBlock 完成的block + */ +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock completeBlock:(PPCompletionBlock)completionBlock; + +@end diff --git a/PPCounter/PPCounter/UILabel+PPCounter.m b/PPCounter/PPCounter/UILabel+PPCounter.m new file mode 100644 index 0000000..6cfe53c --- /dev/null +++ b/PPCounter/PPCounter/UILabel+PPCounter.m @@ -0,0 +1,83 @@ +// +// UILabel+PPCounter.m +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import "UILabel+PPCounter.h" +#import + +@implementation UILabel (PPCounter) + +- (void)pp_fromZeroToNumber:(CGFloat)number formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:0.f toNumber:number duration:1.5f animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromZeroToNumber:(CGFloat)number attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:0.f toNumber:number duration:1.5f animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:1.5f animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:1.5f animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration formatBlock:(PPFormatBlock)formatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:duration animationType:animationType formatBlock:formatBlock completeBlock:nil]; +} + +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock +{ + PPCounterAnimationType animationType = self.counterAnimationType ? self.counterAnimationType : PPCounterAnimationTypeEaseOut; + [self pp_fromNumber:numberA toNumber:numberB duration:duration animationType:animationType attributedFormatBlock:attributedFormatBlock completeBlock:nil]; +} + +#pragma mark - normal font +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType formatBlock:(PPFormatBlock)formatBlock completeBlock:(PPCompletionBlock)completionBlock +{ + + [[PPCounter counter] fromNumber:numberA toNumber:numberB duration:duration animationType:animationType currentNumber:^(CGFloat number) { + + formatBlock ? self.text = formatBlock(number) : nil ; + + } complete:completionBlock]; + +} + +#pragma mark - attributed font +- (void)pp_fromNumber:(CGFloat)numberA toNumber:(CGFloat)numberB duration:(CFTimeInterval)duration animationType:(PPCounterAnimationType)animationType attributedFormatBlock:(PPAttributedFormatBlock)attributedFormatBlock completeBlock:(PPCompletionBlock)completionBlock +{ + [[PPCounter counter] fromNumber:numberA toNumber:numberB duration:duration animationType:animationType currentNumber:^(CGFloat number) { + + attributedFormatBlock ? self.attributedText = attributedFormatBlock(number) : nil ; + + } complete:completionBlock]; +} + +#pragma mark - setter/getter + +- (void)setCounterAnimationType:(PPCounterAnimationType)counterAnimationType +{ + objc_setAssociatedObject(self, &kPPCounterAnimationType, @(counterAnimationType), OBJC_ASSOCIATION_ASSIGN); +} + +- (PPCounterAnimationType)counterAnimationType +{ + return [objc_getAssociatedObject(self, &kPPCounterAnimationType) integerValue]; +} +@end diff --git a/PPCounter/ViewController.h b/PPCounter/ViewController.h new file mode 100644 index 0000000..04b84ac --- /dev/null +++ b/PPCounter/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/PPCounter/ViewController.m b/PPCounter/ViewController.m new file mode 100644 index 0000000..ff7972d --- /dev/null +++ b/PPCounter/ViewController.m @@ -0,0 +1,151 @@ +// +// ViewController.m +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import "ViewController.h" +#import "UILabel+PPCounter.h" +#import "UIButton+PPCounter.h" + +@interface ViewController () + +@property (weak, nonatomic) IBOutlet UILabel *label1; +@property (weak, nonatomic) IBOutlet UILabel *label2; +@property (weak, nonatomic) IBOutlet UILabel *label3; + +@property (weak, nonatomic) IBOutlet UIButton *button1; +@property (weak, nonatomic) IBOutlet UIButton *button2; +@property (weak, nonatomic) IBOutlet UIButton *button3; + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self change:PPCounterAnimationTypeEaseOut]; +} + + +- (IBAction)select:(UISegmentedControl *)sender +{ + [self change:sender.selectedSegmentIndex+1]; +} + +- (void)change:(PPCounterAnimationType)animationType +{ + [self exampleLabel1:animationType]; + [self exampleLabel2:animationType]; + [self exampleLabel3:animationType]; + + [self exampleButton1:animationType]; + [self exampleButton2:animationType]; + [self exampleButton3:animationType]; +} + +#pragma mark - UIlabel + +- (void)exampleLabel1:(PPCounterAnimationType)animationType +{ + // 设置动画类型 + self.label1.counterAnimationType = animationType; + + // 开始计数 + [self.label1 pp_fromZeroToNumber:50 formatBlock:^NSString *(CGFloat number) { + return [NSString stringWithFormat:@"%.0f",number]; + }]; +} + +- (void)exampleLabel2:(PPCounterAnimationType)animationType +{ + + self.label2.counterAnimationType = animationType; + + [self.label2 pp_fromNumber:0 toNumber:100 duration:1.5 animationType:animationType attributedFormatBlock:^NSAttributedString *(CGFloat number) { + + NSString *string = [NSString stringWithFormat:@"%ld%%",(NSInteger)number]; + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string]; + // 设置字体属性 + NSRange range = [string rangeOfString:[NSString stringWithFormat:@"%ld",(NSInteger)number]]; + [attributedString addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:22],NSForegroundColorAttributeName:[UIColor brownColor]} range:range]; + return attributedString; + + } completeBlock:^{ + + self.label2.textColor = [UIColor redColor]; + + }]; + +} + +- (void)exampleLabel3:(PPCounterAnimationType)animationType +{ + + self.label3.counterAnimationType = animationType; + + [self.label3 pp_fromZeroToNumber:2016101 formatBlock:^NSString *(CGFloat number) { + + NSNumberFormatter *formatter = [NSNumberFormatter new]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + formatter.positiveFormat = @"###,##0.00"; + NSNumber *amountNumber = [NSNumber numberWithFloat:number]; + return [NSString stringWithFormat:@"¥%@",[formatter stringFromNumber:amountNumber]]; + + }]; + +} + +#pragma mark - UIButton +- (void)exampleButton1:(PPCounterAnimationType)animationType +{ + // 设置动画类型 + self.button1.counterAnimationType = animationType; + + // 开始计数 + [self.button1 pp_fromZeroToNumber:50 formatBlock:^NSString *(CGFloat number) { + return [NSString stringWithFormat:@"%.0f",number]; + }]; +} + +- (void)exampleButton2:(PPCounterAnimationType)animationType +{ + self.button2.counterAnimationType = animationType; + + [self.button2 pp_fromNumber:0 toNumber:100 duration:1.5 animationType:animationType attributedFormatBlock:^NSAttributedString *(CGFloat number) { + + NSString *string = [NSString stringWithFormat:@"%ld%%",(NSInteger)number]; + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string]; + // 设置字体属性 + NSRange range = [string rangeOfString:[NSString stringWithFormat:@"%ld",(NSInteger)number]]; + [attributedString addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:22],NSForegroundColorAttributeName:[UIColor orangeColor]} range:range]; + return attributedString; + + } completeBlock:^{ + + [self.button2 setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal]; + + }]; +} + +- (void)exampleButton3:(PPCounterAnimationType)animationType +{ + self.button3.counterAnimationType = animationType; + + [self.button3 pp_fromZeroToNumber:2016101 formatBlock:^NSString *(CGFloat number) { + + NSNumberFormatter *formatter = [NSNumberFormatter new]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + formatter.positiveFormat = @"###,##0.00"; + NSNumber *amountNumber = [NSNumber numberWithFloat:number]; + return [NSString stringWithFormat:@"¥%@",[formatter stringFromNumber:amountNumber]]; + + }]; +} + + + +@end diff --git a/PPCounter/main.m b/PPCounter/main.m new file mode 100644 index 0000000..21170c6 --- /dev/null +++ b/PPCounter/main.m @@ -0,0 +1,16 @@ +// +// main.m +// PPCounter +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/PPCounterTests/Info.plist b/PPCounterTests/Info.plist new file mode 100644 index 0000000..6c6c23c --- /dev/null +++ b/PPCounterTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/PPCounterTests/PPCounterTests.m b/PPCounterTests/PPCounterTests.m new file mode 100644 index 0000000..4fe799f --- /dev/null +++ b/PPCounterTests/PPCounterTests.m @@ -0,0 +1,39 @@ +// +// PPCounterTests.m +// PPCounterTests +// +// Created by AndyPang on 16/10/15. +// Copyright © 2016年 AndyPang. All rights reserved. +// + +#import + +@interface PPCounterTests : XCTestCase + +@end + +@implementation PPCounterTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end diff --git a/README.md b/README.md new file mode 100755 index 0000000..99a8c66 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# PPCounter + +一款简单实用的数字加减动画,支持UILabel、UIButton显示 + +![image](https://github.com/jkpang/PPNetworkHelper/blob/master/network.gif) + +##Requirements 要求 +* iOS 7+ +* Xcode 8+ + +##Installation 安装 +###1.手动安装: +`下载DEMO后,将子文件夹PPCounter拖入到项目中, 导入头文件UILabel+PPCounter.h或UIButton+PPCounter.h开始使用` +###2.CocoaPods安装: +first +`pod 'PPCounter',:git => 'https://github.com/jkpang/PPCounter.git'` +then +`pod install或pod install --no-repo-update` + +如果发现pod search PPCounter 不是最新版本,在终端执行pod setup命令更新本地spec镜像缓存(时间可能有点长),重新搜索就OK了 +##Usage 使用方法 +###1. UILabel +####1.1 设置一般字体属性UILabel +```objc +.... +[label pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut formatBlock:^NSString *(CGFloat number) { + // 此处自由拼接内容 + return [NSString stringWithFormat:@"%.2f",number]; +} completeBlock:^{ + + // 完成的回调 +}]; +``` +####1.2 设置富文本字体属性UILabel + +```objc +.... +[label pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut attributedFormatBlock:^NSAttributedString *(CGFloat number) { + + // 此处自由设置富文本属性的内容 + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""]; + return attributedString; +} completeBlock:^{ + + // 完成的回调 +}]; + +``` +###2. UIButton + +####1.1 设置一般字体属性UIButton +```objc +.... +[button pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut formatBlock:^NSString *(CGFloat number) { + // 此处自由拼接内容 + return [NSString stringWithFormat:@"%.2f",number]; +} completeBlock:^{ + + // 完成的回调 +}]; +``` +####1.2 设置富文本字体属性UIButton + +```objc +.... +[button pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut attributedFormatBlock:^NSAttributedString *(CGFloat number) { + + // 此处自由设置富文本属性的内容 + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""]; + return attributedString; +} completeBlock:^{ + + // 完成的回调 +}]; + +``` + +以上就是PPCounter的简单使用方法,更详细的用法请看demo + +###你的star是我持续更新的动力! +=== +##CocoaPods更新日志 +* 2016.10.19(tag:0.1.0)--初始化到CocoaPods; + +##联系方式: +* Weibo : @CoderPang +* Email : jkpang@outlook.com +* QQ : 2406552315 + +##许可证 +PPCounter 使用 MIT 许可证,详情见 LICENSE 文件。 +