├── .gitignore ├── README.md └── WSShiningLabel ├── WSShiningLabel.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── WSShiningLabel ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── WSShiningLabel.h ├── WSShiningLabel.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WSShiningLabel 2 | 闪烁的文字,多种闪烁效果 3 | 4 | 5 | 6 | # PhotoShoot 7 | ![image](https://github.com/Zws-China/.../blob/master/shiningLabel.gif) 8 | 9 | 10 | # How To Use 11 | 12 | ```ruby 13 | #import "WSShiningLabel.h" 14 | 15 | WSShiningLabel *label1 = [[WSShiningLabel alloc] init]; 16 | label1.frame = CGRectMake(50, 35, 200, 25); 17 | label1.text = @"当保护你的她"; 18 | label1.textColor = [UIColor grayColor]; 19 | label1.font = [UIFont systemFontOfSize:20]; 20 | [label1 startShimmer]; // 开启闪烁 21 | [self.view addSubview:label1]; 22 | 23 | 24 | WSShiningLabel *label2 = [[WSShiningLabel alloc] init]; 25 | label2.frame = CGRectMake(50, 105, 200, 25); 26 | label2.text = @"变成要你保护的她"; 27 | label2.textColor = [UIColor grayColor]; 28 | label2.font = [UIFont systemFontOfSize:20]; 29 | label2.shimmerType = ST_RightToLeft; // 滚动方向 right to left 30 | label2.durationTime = 1; // 滚动时间 31 | label2.shimmerColor = [UIColor orangeColor]; // 高亮颜色 32 | [label2 startShimmer]; // 开启闪烁 33 | [self.view addSubview:label2]; 34 | 35 | 36 | WSShiningLabel *label3 = [[WSShiningLabel alloc] init]; 37 | label3.frame = CGRectMake(50, 175, 200, 25); 38 | label3.text = @"当你远离了家"; 39 | label3.textColor = [UIColor grayColor]; 40 | label3.font = [UIFont systemFontOfSize:20]; 41 | label3.shimmerType = ST_AutoReverse; // 滚动方向 左右来回 42 | label3.shimmerWidth = 20; // 高亮的宽度 43 | label3.shimmerRadius = 20; // 阴影的宽度 44 | label3.shimmerColor = [UIColor yellowColor]; // 高亮颜色 45 | [label3 startShimmer]; // 开启闪烁 46 | [self.view addSubview:label3]; 47 | 48 | 49 | WSShiningLabel *label4 = [[WSShiningLabel alloc] init]; 50 | label4.frame = CGRectMake(50, 245, 200, 25); 51 | label4.text = @"努力有了你爱的她"; 52 | label4.textColor = [UIColor grayColor]; 53 | label4.font = [UIFont systemFontOfSize:20]; 54 | label4.shimmerType = ST_ShimmerAll; // 闪烁 55 | label4.durationTime = 0.8; 56 | label4.shimmerColor = [UIColor redColor]; 57 | [label4 startShimmer]; 58 | [self.view addSubview:label4]; 59 | 60 | 61 | 62 | 63 | ``` -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 88F0B82E1DDE94460032ADF3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F0B82D1DDE94460032ADF3 /* main.m */; }; 11 | 88F0B8311DDE94460032ADF3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F0B8301DDE94460032ADF3 /* AppDelegate.m */; }; 12 | 88F0B8341DDE94460032ADF3 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F0B8331DDE94460032ADF3 /* ViewController.m */; }; 13 | 88F0B8371DDE94460032ADF3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 88F0B8351DDE94460032ADF3 /* Main.storyboard */; }; 14 | 88F0B8391DDE94460032ADF3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 88F0B8381DDE94460032ADF3 /* Assets.xcassets */; }; 15 | 88F0B83C1DDE94460032ADF3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 88F0B83A1DDE94460032ADF3 /* LaunchScreen.storyboard */; }; 16 | 88F0B8451DDE94930032ADF3 /* WSShiningLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F0B8441DDE94930032ADF3 /* WSShiningLabel.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 88F0B8291DDE94460032ADF3 /* WSShiningLabel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WSShiningLabel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 88F0B82D1DDE94460032ADF3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | 88F0B82F1DDE94460032ADF3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | 88F0B8301DDE94460032ADF3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | 88F0B8321DDE94460032ADF3 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | 88F0B8331DDE94460032ADF3 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | 88F0B8361DDE94460032ADF3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 88F0B8381DDE94460032ADF3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 88F0B83B1DDE94460032ADF3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 88F0B83D1DDE94460032ADF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 88F0B8431DDE94930032ADF3 /* WSShiningLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSShiningLabel.h; sourceTree = ""; }; 31 | 88F0B8441DDE94930032ADF3 /* WSShiningLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSShiningLabel.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | 88F0B8261DDE94460032ADF3 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 88F0B8201DDE94460032ADF3 = { 46 | isa = PBXGroup; 47 | children = ( 48 | 88F0B82B1DDE94460032ADF3 /* WSShiningLabel */, 49 | 88F0B82A1DDE94460032ADF3 /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | 88F0B82A1DDE94460032ADF3 /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 88F0B8291DDE94460032ADF3 /* WSShiningLabel.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | 88F0B82B1DDE94460032ADF3 /* WSShiningLabel */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 88F0B82F1DDE94460032ADF3 /* AppDelegate.h */, 65 | 88F0B8301DDE94460032ADF3 /* AppDelegate.m */, 66 | 88F0B8321DDE94460032ADF3 /* ViewController.h */, 67 | 88F0B8331DDE94460032ADF3 /* ViewController.m */, 68 | 88F0B8431DDE94930032ADF3 /* WSShiningLabel.h */, 69 | 88F0B8441DDE94930032ADF3 /* WSShiningLabel.m */, 70 | 88F0B8351DDE94460032ADF3 /* Main.storyboard */, 71 | 88F0B8381DDE94460032ADF3 /* Assets.xcassets */, 72 | 88F0B83A1DDE94460032ADF3 /* LaunchScreen.storyboard */, 73 | 88F0B83D1DDE94460032ADF3 /* Info.plist */, 74 | 88F0B82C1DDE94460032ADF3 /* Supporting Files */, 75 | ); 76 | path = WSShiningLabel; 77 | sourceTree = ""; 78 | }; 79 | 88F0B82C1DDE94460032ADF3 /* Supporting Files */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 88F0B82D1DDE94460032ADF3 /* main.m */, 83 | ); 84 | name = "Supporting Files"; 85 | sourceTree = ""; 86 | }; 87 | /* End PBXGroup section */ 88 | 89 | /* Begin PBXNativeTarget section */ 90 | 88F0B8281DDE94460032ADF3 /* WSShiningLabel */ = { 91 | isa = PBXNativeTarget; 92 | buildConfigurationList = 88F0B8401DDE94460032ADF3 /* Build configuration list for PBXNativeTarget "WSShiningLabel" */; 93 | buildPhases = ( 94 | 88F0B8251DDE94460032ADF3 /* Sources */, 95 | 88F0B8261DDE94460032ADF3 /* Frameworks */, 96 | 88F0B8271DDE94460032ADF3 /* Resources */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = WSShiningLabel; 103 | productName = WSShiningLabel; 104 | productReference = 88F0B8291DDE94460032ADF3 /* WSShiningLabel.app */; 105 | productType = "com.apple.product-type.application"; 106 | }; 107 | /* End PBXNativeTarget section */ 108 | 109 | /* Begin PBXProject section */ 110 | 88F0B8211DDE94460032ADF3 /* Project object */ = { 111 | isa = PBXProject; 112 | attributes = { 113 | LastUpgradeCheck = 0730; 114 | ORGANIZATIONNAME = zws; 115 | TargetAttributes = { 116 | 88F0B8281DDE94460032ADF3 = { 117 | CreatedOnToolsVersion = 7.3.1; 118 | }; 119 | }; 120 | }; 121 | buildConfigurationList = 88F0B8241DDE94460032ADF3 /* Build configuration list for PBXProject "WSShiningLabel" */; 122 | compatibilityVersion = "Xcode 3.2"; 123 | developmentRegion = English; 124 | hasScannedForEncodings = 0; 125 | knownRegions = ( 126 | en, 127 | Base, 128 | ); 129 | mainGroup = 88F0B8201DDE94460032ADF3; 130 | productRefGroup = 88F0B82A1DDE94460032ADF3 /* Products */; 131 | projectDirPath = ""; 132 | projectRoot = ""; 133 | targets = ( 134 | 88F0B8281DDE94460032ADF3 /* WSShiningLabel */, 135 | ); 136 | }; 137 | /* End PBXProject section */ 138 | 139 | /* Begin PBXResourcesBuildPhase section */ 140 | 88F0B8271DDE94460032ADF3 /* Resources */ = { 141 | isa = PBXResourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 88F0B83C1DDE94460032ADF3 /* LaunchScreen.storyboard in Resources */, 145 | 88F0B8391DDE94460032ADF3 /* Assets.xcassets in Resources */, 146 | 88F0B8371DDE94460032ADF3 /* Main.storyboard in Resources */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXResourcesBuildPhase section */ 151 | 152 | /* Begin PBXSourcesBuildPhase section */ 153 | 88F0B8251DDE94460032ADF3 /* Sources */ = { 154 | isa = PBXSourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 88F0B8341DDE94460032ADF3 /* ViewController.m in Sources */, 158 | 88F0B8451DDE94930032ADF3 /* WSShiningLabel.m in Sources */, 159 | 88F0B8311DDE94460032ADF3 /* AppDelegate.m in Sources */, 160 | 88F0B82E1DDE94460032ADF3 /* main.m in Sources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXSourcesBuildPhase section */ 165 | 166 | /* Begin PBXVariantGroup section */ 167 | 88F0B8351DDE94460032ADF3 /* Main.storyboard */ = { 168 | isa = PBXVariantGroup; 169 | children = ( 170 | 88F0B8361DDE94460032ADF3 /* Base */, 171 | ); 172 | name = Main.storyboard; 173 | sourceTree = ""; 174 | }; 175 | 88F0B83A1DDE94460032ADF3 /* LaunchScreen.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | 88F0B83B1DDE94460032ADF3 /* Base */, 179 | ); 180 | name = LaunchScreen.storyboard; 181 | sourceTree = ""; 182 | }; 183 | /* End PBXVariantGroup section */ 184 | 185 | /* Begin XCBuildConfiguration section */ 186 | 88F0B83E1DDE94460032ADF3 /* Debug */ = { 187 | isa = XCBuildConfiguration; 188 | buildSettings = { 189 | ALWAYS_SEARCH_USER_PATHS = NO; 190 | CLANG_ANALYZER_NONNULL = YES; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_WARN_BOOL_CONVERSION = YES; 196 | CLANG_WARN_CONSTANT_CONVERSION = YES; 197 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 198 | CLANG_WARN_EMPTY_BODY = YES; 199 | CLANG_WARN_ENUM_CONVERSION = YES; 200 | CLANG_WARN_INT_CONVERSION = YES; 201 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 202 | CLANG_WARN_UNREACHABLE_CODE = YES; 203 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 204 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 205 | COPY_PHASE_STRIP = NO; 206 | DEBUG_INFORMATION_FORMAT = dwarf; 207 | ENABLE_STRICT_OBJC_MSGSEND = YES; 208 | ENABLE_TESTABILITY = YES; 209 | GCC_C_LANGUAGE_STANDARD = gnu99; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 224 | MTL_ENABLE_DEBUG_INFO = YES; 225 | ONLY_ACTIVE_ARCH = YES; 226 | SDKROOT = iphoneos; 227 | }; 228 | name = Debug; 229 | }; 230 | 88F0B83F1DDE94460032ADF3 /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | ALWAYS_SEARCH_USER_PATHS = NO; 234 | CLANG_ANALYZER_NONNULL = YES; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_WARN_BOOL_CONVERSION = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_EMPTY_BODY = YES; 243 | CLANG_WARN_ENUM_CONVERSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu99; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 262 | MTL_ENABLE_DEBUG_INFO = NO; 263 | SDKROOT = iphoneos; 264 | VALIDATE_PRODUCT = YES; 265 | }; 266 | name = Release; 267 | }; 268 | 88F0B8411DDE94460032ADF3 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | INFOPLIST_FILE = WSShiningLabel/Info.plist; 273 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 274 | PRODUCT_BUNDLE_IDENTIFIER = com.sinfotek.WSShiningLabel; 275 | PRODUCT_NAME = "$(TARGET_NAME)"; 276 | }; 277 | name = Debug; 278 | }; 279 | 88F0B8421DDE94460032ADF3 /* Release */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 283 | INFOPLIST_FILE = WSShiningLabel/Info.plist; 284 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 285 | PRODUCT_BUNDLE_IDENTIFIER = com.sinfotek.WSShiningLabel; 286 | PRODUCT_NAME = "$(TARGET_NAME)"; 287 | }; 288 | name = Release; 289 | }; 290 | /* End XCBuildConfiguration section */ 291 | 292 | /* Begin XCConfigurationList section */ 293 | 88F0B8241DDE94460032ADF3 /* Build configuration list for PBXProject "WSShiningLabel" */ = { 294 | isa = XCConfigurationList; 295 | buildConfigurations = ( 296 | 88F0B83E1DDE94460032ADF3 /* Debug */, 297 | 88F0B83F1DDE94460032ADF3 /* Release */, 298 | ); 299 | defaultConfigurationIsVisible = 0; 300 | defaultConfigurationName = Release; 301 | }; 302 | 88F0B8401DDE94460032ADF3 /* Build configuration list for PBXNativeTarget "WSShiningLabel" */ = { 303 | isa = XCConfigurationList; 304 | buildConfigurations = ( 305 | 88F0B8411DDE94460032ADF3 /* Debug */, 306 | 88F0B8421DDE94460032ADF3 /* Release */, 307 | ); 308 | defaultConfigurationIsVisible = 0; 309 | }; 310 | /* End XCConfigurationList section */ 311 | }; 312 | rootObject = 88F0B8211DDE94460032ADF3 /* Project object */; 313 | } 314 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WSShiningLabel.h" 11 | 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController{ 18 | WSShiningLabel *label1; 19 | WSShiningLabel *label2; 20 | WSShiningLabel *label3; 21 | WSShiningLabel *label4; 22 | } 23 | -(void)viewWillAppear:(BOOL)animated { 24 | [super viewWillAppear:animated]; 25 | dispatch_async(dispatch_get_main_queue(), ^{ 26 | label1.isPlaying = false; 27 | label2.isPlaying = false; 28 | label3.isPlaying = false; 29 | label4.isPlaying = false; 30 | [label1 startShimmer]; 31 | [label2 startShimmer]; 32 | [label3 startShimmer]; 33 | [label4 startShimmer]; 34 | }); 35 | } 36 | 37 | 38 | - (void)viewDidLoad { 39 | [super viewDidLoad]; 40 | self.view.backgroundColor = [UIColor colorWithRed:85.0f/255.0f green:85.0f/255.0f blue:85.0f/255.0f alpha:1.0f]; 41 | 42 | label1 = [[WSShiningLabel alloc] init]; 43 | label1.frame = CGRectMake(50, 35, 200, 25); 44 | label1.text = @"当保护你的她"; 45 | label1.textColor = [UIColor grayColor]; 46 | label1.font = [UIFont systemFontOfSize:20]; 47 | [label1 startShimmer]; // 开启闪烁 48 | [self.view addSubview:label1]; 49 | 50 | 51 | label2 = [[WSShiningLabel alloc] init]; 52 | label2.frame = CGRectMake(50, 105, 200, 25); 53 | label2.text = @"变成要你保护的她"; 54 | label2.textColor = [UIColor grayColor]; 55 | label2.font = [UIFont systemFontOfSize:20]; 56 | label2.shimmerType = ST_RightToLeft; // 滚动方向 right to left 57 | label2.durationTime = 1; // 滚动时间 58 | label2.shimmerColor = [UIColor orangeColor]; // 高亮颜色 59 | [label2 startShimmer]; // 开启闪烁 60 | [self.view addSubview:label2]; 61 | 62 | 63 | label3 = [[WSShiningLabel alloc] init]; 64 | label3.frame = CGRectMake(50, 175, 200, 25); 65 | label3.text = @"当你远离了家"; 66 | label3.textColor = [UIColor grayColor]; 67 | label3.font = [UIFont systemFontOfSize:20]; 68 | label3.shimmerType = ST_AutoReverse; 69 | label3.shimmerWidth = 20; // 高亮的宽度 70 | label3.shimmerRadius = 20; // 阴影的宽度 71 | label3.shimmerColor = [UIColor yellowColor]; // 高亮颜色 72 | [label3 startShimmer]; // 开启闪烁 73 | [self.view addSubview:label3]; 74 | 75 | 76 | label4 = [[WSShiningLabel alloc] init]; 77 | label4.frame = CGRectMake(50, 245, 200, 25); 78 | label4.text = @"努力有了你爱的她"; 79 | label4.textColor = [UIColor grayColor]; 80 | label4.font = [UIFont systemFontOfSize:20]; 81 | label4.shimmerType = ST_ShimmerAll; 82 | label4.durationTime = 0.8; 83 | label4.shimmerColor = [UIColor redColor]; 84 | [label4 startShimmer]; 85 | [self.view addSubview:label4]; 86 | 87 | 88 | 89 | } 90 | 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/WSShiningLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // WSShiningLabel.h 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | typedef enum : NSUInteger { 13 | ST_LeftToRight, // 从左到右 14 | ST_RightToLeft, // 从右到左 15 | ST_AutoReverse, // 左右来回 16 | ST_ShimmerAll, // 整体闪烁 17 | } ShimmerType; // 闪烁类型 18 | 19 | 20 | @interface WSShiningLabel : UIView 21 | 22 | // UILabel 常用属性 23 | @property (strong, nonatomic) NSString *text; 24 | @property (strong, nonatomic) UIFont *font; 25 | @property (strong, nonatomic) UIColor *textColor; 26 | @property (strong, nonatomic) NSAttributedString *attributedText; 27 | @property (assign, nonatomic) NSInteger numberOfLines; 28 | 29 | // CKShimmerLabel 属性 30 | @property (assign, nonatomic) ShimmerType shimmerType; // 闪烁类型,默认LeftToRight 31 | @property (assign, nonatomic) BOOL repeat; // 循环播放,默认是 32 | @property (assign, nonatomic) CGFloat shimmerWidth; // 闪烁宽度,默认20 33 | @property (assign, nonatomic) CGFloat shimmerRadius; // 闪烁半径,默认20 34 | @property (strong, nonatomic) UIColor *shimmerColor; // 闪烁颜色,默认白 35 | @property (assign, nonatomic) NSTimeInterval durationTime; // 持续时间,默认2秒 36 | @property (assign, nonatomic) BOOL isPlaying; // 正在播放动画 37 | 38 | - (void)startShimmer; // 开始闪烁,闪烁期间更改上面属性立即生效 39 | - (void)stopShimmer; // 停止闪烁 40 | 41 | @end 42 | 43 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/WSShiningLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // WSShiningLabel.m 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import "WSShiningLabel.h" 10 | 11 | 12 | 13 | @interface WSShiningLabel () 14 | 15 | @property (strong, nonatomic) UILabel *contentLabel; 16 | @property (strong, nonatomic) UILabel *maskLabel; 17 | @property (strong, nonatomic) CAGradientLayer *maskLayer; 18 | @property (assign, nonatomic) CGSize charSize; // 文字 size 19 | @property (assign, nonatomic) CATransform3D startT, endT; // 高亮移动范围 [startT, endT] 20 | @property (strong, nonatomic) CABasicAnimation *translate; // 位移动画 21 | @property (strong, nonatomic) CABasicAnimation *alphaAni; // alpha 动画 22 | 23 | @end 24 | 25 | @implementation WSShiningLabel 26 | 27 | - (instancetype)init { 28 | if (self = [super init]) { 29 | self.frame = CGRectMake(0, 0, 60, 30); 30 | [self myInit]; 31 | } 32 | return self; 33 | } 34 | 35 | - (instancetype)initWithFrame:(CGRect)frame { 36 | if (self = [super initWithFrame:frame]) { 37 | [self myInit]; 38 | } 39 | return self; 40 | } 41 | 42 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 43 | if (self = [super initWithCoder:aDecoder]) { 44 | [self myInit]; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)myInit { 50 | [self addSubview:self.contentLabel]; 51 | [self addSubview:self.maskLabel]; 52 | self.layer.masksToBounds = true; 53 | self.isPlaying = false; 54 | self.startT = CATransform3DIdentity; 55 | self.endT = CATransform3DIdentity; 56 | self.charSize = CGSizeMake(0, 0); 57 | self.shimmerType = ST_LeftToRight; 58 | self.repeat = true; 59 | self.shimmerWidth = 20; 60 | self.shimmerRadius = 20; 61 | self.shimmerColor = [UIColor whiteColor]; 62 | self.durationTime = 2; 63 | 64 | // 进入前台恢复动画 65 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; 66 | } 67 | 68 | - (void)dealloc { 69 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 70 | } 71 | 72 | - (void)layoutSubviews { 73 | [super layoutSubviews]; 74 | 75 | // 刷新布局 76 | self.contentLabel.frame = self.bounds; 77 | self.maskLabel.frame = self.bounds; 78 | self.maskLayer.frame = CGRectMake(0, 0, self.charSize.width, self.charSize.height); 79 | } 80 | 81 | #pragma mark - 属性 set, get 方法 82 | 83 | - (UILabel *)contentLabel { 84 | if (_contentLabel == nil) { 85 | _contentLabel = [[UILabel alloc] initWithFrame:self.bounds]; 86 | _contentLabel.font = [UIFont systemFontOfSize:17]; 87 | _contentLabel.textColor = [UIColor darkGrayColor]; 88 | } 89 | return _contentLabel; 90 | } 91 | 92 | - (UILabel *)maskLabel { 93 | if (_maskLabel == nil) { 94 | _maskLabel = [[UILabel alloc] initWithFrame:self.bounds]; 95 | _maskLabel.font = [UIFont systemFontOfSize:17]; 96 | _maskLabel.textColor = [UIColor darkGrayColor]; 97 | _maskLabel.hidden = true; 98 | } 99 | return _maskLabel; 100 | } 101 | 102 | - (CALayer *)maskLayer { 103 | if (_maskLayer == nil) { 104 | _maskLayer = [[CAGradientLayer alloc] init]; 105 | _maskLayer.backgroundColor = [UIColor clearColor].CGColor; 106 | [self freshMaskLayer]; 107 | } 108 | return _maskLayer; 109 | } 110 | 111 | - (void)setText:(NSString *)text { 112 | if (_text == text) return ; 113 | 114 | _text = text; 115 | self.contentLabel.text = text; 116 | self.charSize = [self.contentLabel.text boundingRectWithSize:self.contentLabel.frame.size options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : self.contentLabel.font} context:nil].size; 117 | [self update]; 118 | } 119 | 120 | - (void)setFont:(UIFont *)font { 121 | if (_font == font) return ; 122 | 123 | _font = font; 124 | self.contentLabel.font = font; 125 | self.charSize = [self.contentLabel.text boundingRectWithSize:self.contentLabel.frame.size options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : self.contentLabel.font} context:nil].size; 126 | [self update]; 127 | } 128 | 129 | - (void)setTextColor:(UIColor *)textColor { 130 | if (_textColor == textColor) return ; 131 | 132 | _textColor = textColor; 133 | self.contentLabel.textColor = textColor; 134 | [self update]; 135 | } 136 | 137 | - (void)setAttributedText:(NSAttributedString *)attributedText { 138 | if (_attributedText == attributedText) return ; 139 | 140 | _attributedText = attributedText; 141 | self.contentLabel.attributedText = attributedText; 142 | [self update]; 143 | } 144 | 145 | - (void)setNumberOfLines:(NSInteger)numberOfLines { 146 | if (_numberOfLines == numberOfLines) return ; 147 | 148 | _numberOfLines = numberOfLines; 149 | self.contentLabel.numberOfLines = numberOfLines; 150 | [self update]; 151 | } 152 | 153 | - (void)setShimmerType:(ShimmerType)shimmerType { 154 | if (_shimmerType == shimmerType) return ; 155 | 156 | _shimmerType = shimmerType; 157 | [self update]; 158 | } 159 | 160 | - (void)setRepeat:(BOOL)repeat { 161 | if (_repeat == repeat) return ; 162 | 163 | _repeat = repeat; 164 | [self update]; 165 | } 166 | 167 | - (void)setShimmerWidth:(CGFloat)shimmerWidth { 168 | if (_shimmerWidth == shimmerWidth) return ; 169 | 170 | _shimmerWidth = shimmerWidth; 171 | [self update]; 172 | } 173 | 174 | - (void)setShimmerRadius:(CGFloat)shimmerRadius { 175 | if (_shimmerRadius == shimmerRadius) return ; 176 | 177 | _shimmerRadius = shimmerRadius; 178 | [self update]; 179 | } 180 | 181 | - (void)setShimmerColor:(UIColor *)shimmerColor { 182 | if (_shimmerColor == shimmerColor) return ; 183 | 184 | _shimmerColor = shimmerColor; 185 | self.maskLabel.textColor = shimmerColor; 186 | [self update]; 187 | } 188 | 189 | - (void)setDurationTime:(NSTimeInterval)durationTime { 190 | if (_durationTime == durationTime) return ; 191 | 192 | _durationTime = durationTime; 193 | [self update]; 194 | } 195 | 196 | - (void)update { 197 | if (self.isPlaying) { // 如果在播放动画,更新动画 198 | [self stopShimmer]; 199 | [self startShimmer]; 200 | } 201 | } 202 | 203 | // 刷新 maskLayer 属性值, transform 值 204 | - (void)freshMaskLayer { 205 | if (self.shimmerType != ST_ShimmerAll) { 206 | _maskLayer.backgroundColor = [UIColor clearColor].CGColor; 207 | _maskLayer.startPoint = CGPointMake(0, 0.5); 208 | _maskLayer.endPoint = CGPointMake(1, 0.5); 209 | _maskLayer.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor]; 210 | 211 | CGFloat w = 1.0; 212 | CGFloat sw = 1.0; 213 | if (self.charSize.width >= 1) { 214 | w = self.shimmerWidth / self.charSize.width * 0.5; 215 | sw = self.shimmerRadius / self.charSize.width; 216 | } 217 | _maskLayer.locations = @[@(0.0), @(0.5 - w - sw), @(0.5 - w), @(0.5 + w), @(0.5 + w + sw), @(1)]; 218 | CGFloat startX = self.charSize.width * (0.5 - w - sw); 219 | CGFloat endX = self.charSize.width * (0.5 + w + sw); 220 | self.startT = CATransform3DMakeTranslation(-endX, 0, 1); 221 | self.endT = CATransform3DMakeTranslation(self.charSize.width - startX, 0, 1); 222 | } else { 223 | _maskLayer.backgroundColor = self.shimmerColor.CGColor; 224 | _maskLayer.colors = nil; 225 | _maskLayer.locations = nil; 226 | } 227 | } 228 | 229 | #pragma mark - 其他方法 230 | 231 | - (void)copyLabel:(UILabel *)dLabel from:(UILabel *)sLabel { 232 | dLabel.attributedText = sLabel.attributedText; 233 | dLabel.text = sLabel.text; 234 | dLabel.font = sLabel.font; 235 | dLabel.numberOfLines = sLabel.numberOfLines; 236 | } 237 | 238 | - (CABasicAnimation *)translate { 239 | if (_translate == nil) { 240 | _translate = [CABasicAnimation animationWithKeyPath:@"transform"]; 241 | } 242 | _translate.duration = self.durationTime; 243 | _translate.repeatCount = self.repeat == true ? MAXFLOAT : 0; 244 | _translate.autoreverses = self.shimmerType == ST_AutoReverse ? true : false; 245 | 246 | return _translate; 247 | } 248 | 249 | - (CABasicAnimation *)alphaAni { 250 | if (_alphaAni == nil) { 251 | _alphaAni = [CABasicAnimation animationWithKeyPath:@"opacity"]; 252 | _alphaAni.repeatCount = MAXFLOAT; 253 | _alphaAni.autoreverses = true; 254 | _alphaAni.fromValue = @(0.0); 255 | _alphaAni.toValue = @(1.0); 256 | } 257 | _alphaAni.duration = self.durationTime; 258 | 259 | return _alphaAni; 260 | } 261 | 262 | - (void)startShimmer { 263 | dispatch_async(dispatch_get_main_queue(), ^{ 264 | // 切换到主线程串行队列,下面代码打包成一个事件(原子操作),加到runloop,就不用担心 isPlaying 被多个线程同时修改 265 | // dispatch_async() 不 strong 持有本 block,也不用担心循环引用 266 | if (self.isPlaying == true) return ; 267 | self.isPlaying = true; 268 | 269 | [self copyLabel:self.maskLabel from:self.contentLabel]; 270 | self.maskLabel.hidden = false; 271 | 272 | // [self.layer addSublayer:self.maskLayer]; 273 | [self.maskLayer removeFromSuperlayer]; 274 | [self freshMaskLayer]; 275 | [self.maskLabel.layer addSublayer:self.maskLayer]; 276 | self.maskLabel.layer.mask = self.maskLayer; 277 | 278 | switch (self.shimmerType) { 279 | case ST_LeftToRight: { 280 | self.maskLayer.transform = self.startT; 281 | self.translate.fromValue = [NSValue valueWithCATransform3D:self.startT]; 282 | self.translate.toValue = [NSValue valueWithCATransform3D:self.endT]; 283 | [self.maskLayer removeAllAnimations]; 284 | [self.maskLayer addAnimation:self.translate forKey:@"start"]; 285 | break; 286 | } 287 | case ST_RightToLeft: { 288 | self.maskLayer.transform = self.endT; 289 | self.translate.fromValue = [NSValue valueWithCATransform3D:self.endT]; 290 | self.translate.toValue = [NSValue valueWithCATransform3D:self.startT]; 291 | [self.maskLayer removeAllAnimations]; 292 | [self.maskLayer addAnimation:self.translate forKey:@"start"]; 293 | break; 294 | } 295 | case ST_AutoReverse : { 296 | self.maskLayer.transform = self.startT; 297 | self.translate.fromValue = [NSValue valueWithCATransform3D:self.startT]; 298 | self.translate.toValue = [NSValue valueWithCATransform3D:self.endT]; 299 | [self.maskLayer removeAllAnimations]; 300 | [self.maskLayer addAnimation:self.translate forKey:@"start"]; 301 | break; 302 | } 303 | case ST_ShimmerAll : { 304 | self.maskLayer.transform = CATransform3DIdentity; 305 | [self.maskLayer removeAllAnimations]; 306 | [self.maskLayer addAnimation:self.alphaAni forKey:@"start"]; 307 | break; 308 | } 309 | default: break; 310 | } 311 | }); 312 | } 313 | 314 | - (void)stopShimmer { 315 | dispatch_async(dispatch_get_main_queue(), ^{ 316 | if (self.isPlaying == false) return ; 317 | self.isPlaying = false; 318 | 319 | [self.maskLayer removeAllAnimations]; 320 | [self.maskLayer removeFromSuperlayer]; 321 | self.maskLabel.hidden = true; 322 | }); 323 | } 324 | 325 | - (void)willEnterForeground { 326 | dispatch_async(dispatch_get_main_queue(), ^{ 327 | self.isPlaying = false; 328 | [self startShimmer]; 329 | }); 330 | } 331 | 332 | @end 333 | -------------------------------------------------------------------------------- /WSShiningLabel/WSShiningLabel/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WSShiningLabel 4 | // 5 | // Created by iMac on 16/11/18. 6 | // Copyright © 2016年 zws. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------