├── .gitignore ├── LICENSE ├── README.md ├── WHKit.podspec ├── WHKit ├── CALayer+WHLayer.h ├── CALayer+WHLayer.m ├── Foundation+Safe.h ├── Foundation+Safe.m ├── NSArray+WHArray.h ├── NSArray+WHArray.m ├── NSDate+WHDate.h ├── NSDate+WHDate.m ├── NSDictionary+WHDictionary.h ├── NSDictionary+WHDictionary.m ├── NSFileManager+WHFileManager.h ├── NSFileManager+WHFileManager.m ├── NSNumber+WHNumber.h ├── NSNumber+WHNumber.m ├── NSObject+WHObject.h ├── NSObject+WHObject.m ├── NSObject+WHRuntime.h ├── NSObject+WHRuntime.m ├── NSString+WHString.h ├── NSString+WHString.m ├── NSTimer+WHTimer.h ├── NSTimer+WHTimer.m ├── SerializeKit.h ├── UIAlertController+WHAlert.h ├── UIAlertController+WHAlert.m ├── UIBarButtonItem+WHBarButtonItem.h ├── UIBarButtonItem+WHBarButtonItem.m ├── UIButton+WHButton.h ├── UIButton+WHButton.m ├── UIColor+WHColor.h ├── UIColor+WHColor.m ├── UIDevice+WHDevice.h ├── UIDevice+WHDevice.m ├── UIImage+WHImage.h ├── UIImage+WHImage.m ├── UILabel+WHLabel.h ├── UILabel+WHLabel.m ├── UINavigationController+WHNavigationController.h ├── UINavigationController+WHNavigationController.m ├── UIScrollView+WHScrollView.h ├── UIScrollView+WHScrollView.m ├── UITableView+WHTableView.h ├── UITableView+WHTableView.m ├── UIView+WHView.h ├── UIView+WHView.m ├── UIViewController+WHVC.h ├── UIViewController+WHVC.m ├── WHKit.h ├── WHMacro.h ├── WHMethods.h ├── WHMethods.m └── WHSingleton.h └── WHKitDemo ├── Podfile ├── Podfile.lock ├── Pods ├── Local Podspecs │ └── WHKit.podspec.json ├── Manifest.lock ├── Pods.xcodeproj │ └── project.pbxproj └── Target Support Files │ ├── Pods-WHKitDemo │ ├── Pods-WHKitDemo-Info.plist │ ├── Pods-WHKitDemo-acknowledgements.markdown │ ├── Pods-WHKitDemo-acknowledgements.plist │ ├── Pods-WHKitDemo-dummy.m │ ├── Pods-WHKitDemo-frameworks-Debug-input-files.xcfilelist │ ├── Pods-WHKitDemo-frameworks-Debug-output-files.xcfilelist │ ├── Pods-WHKitDemo-frameworks-Release-input-files.xcfilelist │ ├── Pods-WHKitDemo-frameworks-Release-output-files.xcfilelist │ ├── Pods-WHKitDemo-frameworks.sh │ ├── Pods-WHKitDemo-umbrella.h │ ├── Pods-WHKitDemo.debug.xcconfig │ ├── Pods-WHKitDemo.modulemap │ └── Pods-WHKitDemo.release.xcconfig │ └── WHKit │ ├── WHKit-Info.plist │ ├── WHKit-dummy.m │ ├── WHKit-prefix.pch │ ├── WHKit-umbrella.h │ ├── WHKit.debug.xcconfig │ ├── WHKit.modulemap │ ├── WHKit.release.xcconfig │ └── WHKit.xcconfig ├── WHKitDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── WHKitDemo.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist └── WHKitDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── SceneDelegate.h ├── SceneDelegate.m ├── ViewController.h ├── ViewController.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 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 wuhao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WHKit 2 | 3 | ### 使用方法 4 | ```objc 5 | pod 'WHKit', '~>1.9.0' 6 | 7 | 也可以直接把WHKit文件添加进工程中 8 | 在pch文件中:#import "WHKit.h" 9 | ``` 10 | 11 | ### 这个文件中包含了如下内容 12 | ```objc 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | #import 23 | #import 24 | #import 25 | #import 26 | #import 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | #import 33 | #import 34 | #import 35 | #import 36 | 37 | #import 38 | 39 | #import 40 | #import 41 | #import 42 | ``` 43 | 44 | ### 例子 Example 45 | ```objc 46 | /** 点击按钮 */ 47 | [button wh_addActionHandler:^{ 48 | NSLog(@"我被点击了"); 49 | }]; 50 | 51 | /** UIView分类, 触发view点击事件 */ 52 | [view wh_addTapActionWithBlock:^(UITapGestureRecognizer *gestureRecoginzer) { 53 | NSLog(@"点击了view"); 54 | }]; 55 | 56 | /** 是否为iPhone X的宏,返回BOOL值 */ 57 | if (kIs_iPhoneX ) { ... } 58 | 59 | /** 快速创建单例 */ 60 | WHSingletonH(ClassName) 61 | WHSingletonM(ClassName) 62 | 63 | /** 高效添加圆角 */ 64 | - (UIImage*)wh_imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size; 65 | 66 | /** 反转数组 */ 67 | - (NSArray *)wh_reverseArray; 68 | 69 | /** 根据左边和右边的字符串,获得中间特定字符串 */ 70 | - (NSString*)wh_substringWithinBoundsLeft:(NSString*)strLeft right:(NSString*)strRight; 71 | 72 | /** 渐变颜色*/ 73 | + (UIColor*)wh_gradientFromColor:(UIColor*)fromColor toColor:(UIColor*)toColor withHeight:(CGFloat)height; 74 | 75 | /** 十六进制字符串颜色 */ 76 | + (UIColor *)wh_colorWithHexString:(NSString *)color alpha:(CGFloat)alpha; 77 | 78 | /** 根据Date返回日期字符串 */ 79 | + (NSString *)stringWithDate:(NSDate *)date format:(NSString *)format; 80 | 81 | /** 是否润年 */ 82 | - (BOOL)isLeapYear; 83 | 84 | /** 是否是今天 */ 85 | - (BOOL)isToday; 86 | ``` 87 | 88 | ### MIT LICENSE 89 | -------------------------------------------------------------------------------- /WHKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "WHKit" 4 | s.version = "1.9.0" 5 | s.summary = "Make development easier." 6 | s.homepage = "https://github.com/remember17/WHKit" 7 | s.license = "MIT" 8 | s.author = { "wuhao" => "503007958@qq.com" } 9 | s.platform = :ios, "11.0" 10 | s.source = { :git => "https://github.com/remember17/WHKit.git", :tag => s.version } 11 | s.source_files = "WHKit", "WHKit/*.{h,m}" 12 | s.framework = "UIKit" 13 | s.requires_arc = true 14 | 15 | end 16 | -------------------------------------------------------------------------------- /WHKit/CALayer+WHLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+WHLayer.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/7/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CALayer (WHLayer) 12 | 13 | /** 左右抖动 */ 14 | -(void)shake; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /WHKit/CALayer+WHLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+WHLayer.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/7/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "CALayer+WHLayer.h" 10 | 11 | @implementation CALayer (WHLayer) 12 | 13 | -(void)shake{ 14 | CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"]; 15 | CGFloat shakeWidth = 16; 16 | keyAnimation.values = @[@(-shakeWidth),@(0),@(shakeWidth),@(0),@(-shakeWidth),@(0),@(shakeWidth),@(0)]; 17 | //时长 18 | keyAnimation.duration = .1f; 19 | //重复 20 | keyAnimation.repeatCount =2; 21 | //移除 22 | keyAnimation.removedOnCompletion = YES; 23 | [self addAnimation:keyAnimation forKey:@"shake"]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /WHKit/Foundation+Safe.h: -------------------------------------------------------------------------------- 1 | // 2 | // Foundation+Safe.h 3 | // WHKitDemo 4 | // 5 | // Created by 吴浩 on 2018/6/12. 6 | // Copyright © 2018年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray<__covariant ObjectType> (Safe) 12 | 13 | - (nullable ObjectType)safeObjectAtIndex:(NSUInteger)index; 14 | 15 | - (nullable ObjectType)safeObjectAtIndex:(NSUInteger)index defaultValue:(nullable ObjectType)defaultValue; 16 | 17 | + (instancetype _Nullable )safeArrayWithObject:(ObjectType _Nonnull)object; 18 | 19 | - (nullable NSArray *)safeSubarrayWithRange:(NSRange)range; 20 | 21 | - (NSUInteger)safeIndexOfObject:(ObjectType _Nonnull)anObject; 22 | 23 | - (NSUInteger)safeIndexOfObject:(ObjectType _Nonnull)anObject defaultIndex:(NSUInteger)defaultIndex; 24 | 25 | @end 26 | 27 | @interface NSMutableArray (Safe) 28 | 29 | - (void)safeAddObject:(ObjectType _Nonnull)object; 30 | 31 | - (void)safeInsertObject:(ObjectType _Nonnull)object atIndex:(NSUInteger)index; 32 | 33 | - (void)safeInsertObjects:(NSArray * _Nonnull)objects atIndexes:(NSIndexSet * _Nonnull)indexs; 34 | 35 | - (void)safeRemoveObjectAtIndex:(NSUInteger)index; 36 | 37 | - (void)safeRemoveObjectsInRange:(NSRange)range; 38 | 39 | - (nullable ObjectType)safeObjectAtIndexedSubscript:(NSUInteger)index; 40 | 41 | @end 42 | 43 | @interface NSDictionary<__covariant KeyType, __covariant ObjectType> (Safe) 44 | 45 | + (instancetype _Nullable )safeDictionaryWithObject:(ObjectType _Nonnull)object forKey:(KeyType _Nonnull)key; 46 | 47 | @end 48 | 49 | @interface NSMutableDictionary (safe) 50 | 51 | - (void)safeSetObject:(ObjectType _Nonnull)aObj forKey:(KeyType _Nonnull)aKey; 52 | 53 | @end 54 | 55 | @interface NSString (Safe) 56 | 57 | - (nullable NSString *)safeSubstringFromIndex:(NSUInteger)from; 58 | 59 | - (nullable NSString *)safeSubstringToIndex:(NSUInteger)to; 60 | 61 | - (nullable NSString *)safeSubstringWithRange:(NSRange)range; 62 | 63 | - (NSRange)safeRangeOfString:(nullable NSString *)aString; 64 | 65 | - (NSRange)safeRangeOfString:(nullable NSString *)aString options:(NSStringCompareOptions)mask; 66 | 67 | - (NSString *_Nullable)safeStringByAppendingString:(NSString * _Nonnull)aString; 68 | 69 | - (instancetype _Nullable )safeInitWithString:(NSString * _Nonnull)aString; 70 | 71 | + (instancetype _Nullable )safeStringWithString:(NSString * _Nonnull)string; 72 | 73 | @end 74 | 75 | @interface NSMutableString (Safe) 76 | 77 | - (void)safeInsertString:(NSString * _Nonnull)aString atIndex:(NSUInteger)loc; 78 | 79 | - (void)safeAppendString:(NSString * _Nonnull)aString; 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /WHKit/Foundation+Safe.m: -------------------------------------------------------------------------------- 1 | // 2 | // Foundation+Safe.m 3 | // WHKitDemo 4 | // 5 | // Created by 吴浩 on 2018/6/12. 6 | // Copyright © 2018年 remember17. All rights reserved. 7 | // 8 | 9 | #import "Foundation+Safe.h" 10 | #import 11 | 12 | @implementation NSArray (Safe) 13 | 14 | + (void)load { 15 | method_setImplementation(class_getInstanceMethod(self, @selector(objectAtIndexedSubscript:)), class_getMethodImplementation(self, @selector(safeObjectAtIndexedSubscript:))); 16 | } 17 | 18 | - (id)safeObjectAtIndexedSubscript:(NSUInteger)index { 19 | if (index >= self.count) { 20 | NSAssert(FALSE, @"数组越界了"); 21 | return nil; 22 | } else { 23 | return [self objectAtIndex:index]; 24 | } 25 | } 26 | 27 | - (id)safeObjectAtIndex:(NSUInteger)index { 28 | if (index >= self.count) { 29 | NSAssert(FALSE, @"数组越界了"); 30 | return nil; 31 | } else { 32 | return [self objectAtIndex:index]; 33 | } 34 | } 35 | 36 | - (id)safeObjectAtIndex:(NSUInteger)index defaultValue:(id)defaultValue { 37 | if (index >= self.count) { 38 | return defaultValue; 39 | } else { 40 | return [self objectAtIndex:index]; 41 | } 42 | } 43 | 44 | + (instancetype)safeArrayWithObject:(id)object { 45 | if (object == nil) { 46 | return [self array]; 47 | } else { 48 | return [self arrayWithObject:object]; 49 | } 50 | } 51 | 52 | - (NSArray *)safeSubarrayWithRange:(NSRange)range { 53 | NSUInteger location = range.location; 54 | NSUInteger length = range.length; 55 | if (location + length > self.count) { 56 | if ((location + length) > self.count) { 57 | length = (self.count - location); 58 | return [self safeSubarrayWithRange:NSMakeRange(location, length)]; 59 | } 60 | return nil; 61 | } else { 62 | return [self subarrayWithRange:range]; 63 | } 64 | } 65 | 66 | - (NSUInteger)safeIndexOfObject:(id)anObject { 67 | if (anObject == nil) { 68 | return NSNotFound; 69 | } else { 70 | return [self indexOfObject:anObject]; 71 | } 72 | } 73 | 74 | - (NSUInteger)safeIndexOfObject:(id)anObject defaultIndex:(NSUInteger)defaultIndex { 75 | if (anObject == nil) { 76 | return defaultIndex; 77 | } else { 78 | return [self indexOfObject:anObject]; 79 | } 80 | } 81 | 82 | @end 83 | 84 | @implementation NSMutableArray (Safe) 85 | 86 | + (void)load { 87 | method_setImplementation(class_getInstanceMethod(self, @selector(setObject:atIndexedSubscript:)), class_getMethodImplementation(self, @selector(safeSetObject:atIndexedSubscript:))); 88 | 89 | method_setImplementation(class_getInstanceMethod(NSClassFromString(@"__NSArrayM"), @selector(objectAtIndexedSubscript:)), class_getMethodImplementation(self, @selector(safeObjectAtIndexedSubscript:))); 90 | } 91 | 92 | - (void)safeSetObject:(id)obj atIndexedSubscript:(NSUInteger)idx { 93 | NSAssert(obj, @"setObject:atIndexedSubscript: 异常,obj为空"); 94 | if (obj == nil) { 95 | return; 96 | } 97 | 98 | if (self.count < idx) { 99 | NSAssert(obj, @"setObject:atIndexedSubscript: 异常,index越界"); 100 | return; 101 | } 102 | 103 | if (idx == self.count) { 104 | [self addObject:obj]; 105 | } else { 106 | [self replaceObjectAtIndex:idx withObject:obj]; 107 | } 108 | } 109 | 110 | - (void)safeAddObject:(id)object { 111 | if (object == nil) { 112 | return; 113 | } else { 114 | [self addObject:object]; 115 | } 116 | } 117 | 118 | - (void)safeInsertObject:(id)object atIndex:(NSUInteger)index { 119 | if (object == nil) { 120 | return; 121 | } else if (index > self.count) { 122 | return; 123 | } else { 124 | [self insertObject:object atIndex:index]; 125 | } 126 | } 127 | 128 | - (void)safeInsertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexs { 129 | NSUInteger firstIndex = indexs.firstIndex; 130 | if (indexs == nil) { 131 | return; 132 | } else if (indexs.count != objects.count || firstIndex > objects.count) { 133 | return; 134 | } else { 135 | [self insertObjects:objects atIndexes:indexs]; 136 | } 137 | } 138 | 139 | - (void)safeRemoveObjectAtIndex:(NSUInteger)index { 140 | if (index >= self.count) { 141 | return; 142 | } else { 143 | [self removeObjectAtIndex:index]; 144 | } 145 | } 146 | 147 | - (void)safeRemoveObjectsInRange:(NSRange)range { 148 | NSUInteger location = range.location; 149 | NSUInteger length = range.length; 150 | if (location + length > self.count) { 151 | return; 152 | } else { 153 | [self removeObjectsInRange:range]; 154 | } 155 | } 156 | 157 | - (id)safeObjectAtIndexedSubscript:(NSUInteger)index { 158 | if (index >= self.count) { 159 | NSAssert(FALSE, @"数组越界了"); 160 | return nil; 161 | } else { 162 | return [self objectAtIndex:index]; 163 | } 164 | } 165 | 166 | @end 167 | 168 | @implementation NSDictionary (Safe) 169 | 170 | + (instancetype)safeDictionaryWithObject:(id)object forKey:(id )key { 171 | if (!object || !key) { 172 | return [self dictionary]; 173 | } else { 174 | return [self dictionaryWithObject:object forKey:key]; 175 | } 176 | } 177 | 178 | @end 179 | 180 | @implementation NSMutableDictionary (safe) 181 | 182 | + (void)load { 183 | method_setImplementation(class_getInstanceMethod(self, @selector(setObject:forKeyedSubscript:)), class_getMethodImplementation(self, @selector(safeSetObject:forKeyedSubscript:))); 184 | } 185 | 186 | - (void)safeSetObject:(id)obj forKeyedSubscript:(id )key { 187 | NSAssert(key, @"setObject:forKeyedSubscript: 异常"); 188 | if (!key) { 189 | return; 190 | } 191 | 192 | if (!obj) { 193 | [self removeObjectForKey:key]; 194 | } else { 195 | [self setObject:obj forKey:key]; 196 | } 197 | } 198 | 199 | - (void)safeSetObject:(id)aObj forKey:(id )aKey { 200 | if (aObj && aKey) { 201 | [self setObject:aObj forKey:aKey]; 202 | } else { 203 | return; 204 | } 205 | } 206 | 207 | @end 208 | 209 | @implementation NSString (Safe) 210 | 211 | - (NSString *)safeSubstringFromIndex:(NSUInteger)from { 212 | if (from > self.length) { 213 | return nil; 214 | } else { 215 | return [self substringFromIndex:from]; 216 | } 217 | } 218 | 219 | - (NSString *)safeSubstringToIndex:(NSUInteger)to { 220 | if (to > self.length) { 221 | return nil; 222 | } else { 223 | return [self substringToIndex:to]; 224 | } 225 | } 226 | 227 | - (NSString *)safeSubstringWithRange:(NSRange)range { 228 | NSUInteger location = range.location; 229 | NSUInteger length = range.length; 230 | if (location + length > self.length) { 231 | return nil; 232 | } else { 233 | return [self substringWithRange:range]; 234 | } 235 | } 236 | 237 | - (NSRange)safeRangeOfString:(NSString *)aString { 238 | if (aString == nil) { 239 | return NSMakeRange(NSNotFound, 0); 240 | } else { 241 | return [self rangeOfString:aString]; 242 | } 243 | } 244 | 245 | - (NSRange)safeRangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask { 246 | if (aString == nil) { 247 | return NSMakeRange(NSNotFound, 0); 248 | } else { 249 | return [self rangeOfString:aString options:mask]; 250 | } 251 | } 252 | 253 | - (NSString *)safeStringByAppendingString:(NSString *)aString { 254 | if (aString == nil) { 255 | return [self stringByAppendingString:@""]; 256 | } else { 257 | return [self stringByAppendingString:aString]; 258 | } 259 | } 260 | 261 | - (instancetype)safeInitWithString:(NSString *)aString { 262 | if (aString == nil) { 263 | return [self initWithString:@""]; 264 | } else { 265 | return [self initWithString:aString]; 266 | } 267 | } 268 | 269 | + (instancetype)safeStringWithString:(NSString *)string { 270 | if (string == nil) { 271 | return [self stringWithString:@""]; 272 | } else { 273 | return [self stringWithString:string]; 274 | } 275 | } 276 | 277 | @end 278 | 279 | @implementation NSMutableString (Safe) 280 | 281 | - (void)safeInsertString:(NSString *)aString atIndex:(NSUInteger)loc { 282 | if (aString == nil) { 283 | return; 284 | } else if (loc > self.length) { 285 | return; 286 | } else { 287 | [self insertString:aString atIndex:loc]; 288 | } 289 | } 290 | 291 | - (void)safeAppendString:(NSString *)aString { 292 | if (aString == nil) { 293 | return; 294 | } else { 295 | [self appendString:aString]; 296 | } 297 | } 298 | 299 | @end 300 | 301 | -------------------------------------------------------------------------------- /WHKit/NSArray+WHArray.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+WHArray.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (WHArray) 12 | 13 | /** 反转数组 */ 14 | - (NSArray *)wh_reverseArray; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /WHKit/NSArray+WHArray.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+WHArray.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "NSArray+WHArray.h" 10 | 11 | @implementation NSArray (WHArray) 12 | 13 | - (NSArray *)wh_reverseArray { 14 | NSMutableArray *arrayTemp = [NSMutableArray arrayWithCapacity:[self count]]; 15 | NSEnumerator *enumerator = [self reverseObjectEnumerator]; 16 | for (id element in enumerator) { 17 | [arrayTemp addObject:element]; 18 | } 19 | return arrayTemp; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /WHKit/NSDate+WHDate.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+WHDate.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (WHDate) 12 | 13 | /** 根据日期返回字符串 */ 14 | + (NSString *)stringWithDate:(NSDate *)date format:(NSString *)format; 15 | 16 | /** 对象方法,返回时间字符串 */ 17 | - (NSString *)stringWithFormat:(NSString *)format; 18 | 19 | /** 根据字符串返回NSDate */ 20 | + (NSDate *)dateWithString:(NSString *)string format:(NSString *)format; 21 | 22 | /** 根据TimeInterval获取字符串,带有时区偏移 */ 23 | + (NSString *)stringWithTimeInterval:(unsigned int)time Formatter:(NSString *)format; 24 | 25 | /** 根据字符串和格式获取TimeInterval时间,带有时区偏移 */ 26 | + (NSTimeInterval )timeIntervalFromString:(NSString *)timeStr Formatter:(NSString *)format; 27 | 28 | /** 当前TimeInterval时间,带有时区偏移 */ 29 | + (NSTimeInterval )now; 30 | 31 | /** yyyy-MM-dd HH:mm:ss格式的当前时间 */ 32 | + (NSString *)stringNowWithFullFormatter; 33 | 34 | /** YYYY-MM-dd格式的日期字符串 */ 35 | - (NSString *)formatYMD; 36 | 37 | /** YYYY-MM-dd格式的日期字符串 */ 38 | + (NSString *)formatYMD:(NSDate *)date; 39 | 40 | /** 自定义格式的当前时间 */ 41 | + (NSString *)stringNowWithFormatter:(NSString *)format; 42 | 43 | - (NSUInteger)day; 44 | - (NSUInteger)month; 45 | - (NSUInteger)year; 46 | - (NSUInteger)hour; 47 | - (NSUInteger)minute; 48 | - (NSUInteger)second; 49 | + (NSUInteger)day:(NSDate *)date; 50 | + (NSUInteger)month:(NSDate *)date; 51 | + (NSUInteger)year:(NSDate *)date; 52 | + (NSUInteger)hour:(NSDate *)date; 53 | + (NSUInteger)minute:(NSDate *)date; 54 | + (NSUInteger)second:(NSDate *)date; 55 | 56 | /** 一年的总天数 */ 57 | - (NSUInteger)daysInYear; 58 | 59 | /** 一年的总天数 */ 60 | + (NSUInteger)daysInYear:(NSDate *)date; 61 | 62 | /** 判断是否是润年 */ 63 | - (BOOL)isLeapYear; 64 | 65 | /** 判断是否是润年 */ 66 | + (BOOL)isLeapYear:(NSDate *)date; 67 | 68 | /** 获取该日期是该年的第几周 */ 69 | - (NSUInteger)weekOfYear; 70 | 71 | /** 获取该日期是该年的第几周 */ 72 | + (NSUInteger)weekOfYear:(NSDate *)date; 73 | 74 | /** 当前月一共有几周(可能为4,5,6) */ 75 | - (NSUInteger)weeksOfMonth; 76 | 77 | /** 当前月一共有几周(可能为4,5,6) */ 78 | + (NSUInteger)weeksOfMonth:(NSDate *)date; 79 | 80 | /** 获取该月的第一天 */ 81 | - (NSDate *)begindayOfMonth; 82 | 83 | /** 获取该月的第一天 */ 84 | + (NSDate *)begindayOfMonth:(NSDate *)date; 85 | 86 | /** 获取该月的最后一天 */ 87 | - (NSDate *)lastdayOfMonth; 88 | 89 | /** 获取该月的最后一天 */ 90 | + (NSDate *)lastdayOfMonth:(NSDate *)date; 91 | 92 | /** day天后的日期(若day为负数,则为|day|天前的日期) */ 93 | - (NSDate *)dateAfterDay:(NSUInteger)day; 94 | 95 | /** day天后的日期(若day为负数,则为|day|天前的日期) */ 96 | + (NSDate *)dateAfterDate:(NSDate *)date day:(NSInteger)day; 97 | 98 | /** month月后的日期(若month为负数,则为|month|月前的日期) */ 99 | - (NSDate *)dateAfterMonth:(NSUInteger)month; 100 | 101 | /** month月后的日期(若month为负数,则为|month|月前的日期) */ 102 | + (NSDate *)dateAfterDate:(NSDate *)date month:(NSInteger)month; 103 | 104 | /** numYears年后的日期 */ 105 | - (NSDate *)offsetYears:(int)numYears; 106 | 107 | /** numYears年后的日期 */ 108 | + (NSDate *)offsetYears:(int)numYears fromDate:(NSDate *)fromDate; 109 | 110 | /** numHours小时后的日期 */ 111 | - (NSDate *)offsetHours:(int)hours; 112 | 113 | /** numHours小时后的日期 */ 114 | + (NSDate *)offsetHours:(int)numHours fromDate:(NSDate *)fromDate; 115 | 116 | /** 距离该日期前几天 */ 117 | - (NSUInteger)daysAgo; 118 | 119 | /** 距离该日期前几天 */ 120 | + (NSUInteger)daysAgo:(NSDate *)date; 121 | 122 | /** 星期几 */ 123 | - (NSInteger)weekday; 124 | 125 | /** 星期几 */ 126 | + (NSInteger)weekday:(NSDate *)date; 127 | 128 | /** 获取星期几(字符串 */ 129 | - (NSString *)dayFromWeekday; 130 | 131 | /** 获取星期几(字符串 */ 132 | + (NSString *)dayFromWeekday:(NSDate *)date; 133 | 134 | /** 获取阴历 */ 135 | - (NSString*)lunar; 136 | 137 | /** 日期是否相等 */ 138 | - (BOOL)isSameDay:(NSDate *)anotherDate; 139 | 140 | /** 是否是今天 */ 141 | - (BOOL)isToday; 142 | 143 | /** 增加几天之后的日期 */ 144 | - (NSDate *)dateByAddingDays:(NSUInteger)days; 145 | 146 | /** 获取英文字符串月份 */ 147 | + (NSString *)monthWithMonthNumber:(NSInteger)month; 148 | 149 | /** 获取指定月份的天数 */ 150 | - (NSUInteger)daysInMonth:(NSUInteger)month; 151 | 152 | /** 获取指定月份的天数 */ 153 | + (NSUInteger)daysInMonth:(NSDate *)date month:(NSUInteger)month; 154 | 155 | /** 获取当前月份的天数 */ 156 | - (NSUInteger)daysInMonth; 157 | 158 | /** 获取当前月份的天数 */ 159 | + (NSUInteger)daysInMonth:(NSDate *)date; 160 | 161 | /** 返回x分钟前/x小时前/昨天/x天前/x个月前/x年前 */ 162 | - (NSString *)timeInfo; 163 | 164 | /** 返回x分钟前/x小时前/昨天/x天前/x个月前/x年前 */ 165 | + (NSString *)timeInfoWithDate:(NSDate *)date; 166 | 167 | /** 返回x分钟前/x小时前/昨天/x天前/x个月前/x年前 */ 168 | + (NSString *)timeInfoWithDateString:(NSString *)dateString; 169 | 170 | - (NSString *)ymdFormat; 171 | - (NSString *)hmsFormat; 172 | - (NSString *)ymdHmsFormat; 173 | + (NSString *)ymdFormat; 174 | + (NSString *)hmsFormat; 175 | + (NSString *)ymdHmsFormat; 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /WHKit/NSDictionary+WHDictionary.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+WHDictionary.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (WHDictionary) 12 | 13 | /** 一般模型属性 */ 14 | -(void)wh_createProperty; 15 | 16 | /** 网络模型属性 */ 17 | -(void)wh_createNetProperty; 18 | 19 | /** 合并两个NSDictionary */ 20 | + (NSDictionary *)dictionaryByMerging:(NSDictionary *)dict1 with:(NSDictionary *)dict2; 21 | 22 | /** 并入一个NSDictionary */ 23 | - (NSDictionary *)dictionaryByMergingWith:(NSDictionary *)dict; 24 | 25 | /** 拼接字典 */ 26 | - (NSDictionary *)dictionaryByAddingEntriesFromDictionary:(NSDictionary *)dictionary; 27 | 28 | /** 删除某些key值 */ 29 | - (NSDictionary *)dictionaryByRemovingEntriesWithKeys:(NSSet *)keys; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /WHKit/NSDictionary+WHDictionary.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+WHDictionary.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+WHDictionary.h" 10 | 11 | @implementation NSDictionary (WHDictionary) 12 | 13 | #pragma mark - 网络模型属性 14 | -(void)wh_createNetProperty{ 15 | NSMutableString *codes=[NSMutableString string]; 16 | [self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) { 17 | NSString *code; 18 | if ([value isKindOfClass:[NSString class]]) { 19 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",key]; 20 | }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){ 21 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) BOOL %@;",key]; 22 | }else if ([value isKindOfClass:[NSNumber class]]) { 23 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) NSNumber *%@;",key]; 24 | }else if ([value isKindOfClass:[NSArray class]]) { 25 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) NSArray *%@;",key]; 26 | }else if ([value isKindOfClass:[NSDictionary class]]) { 27 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) NSDictionary *%@;",key]; 28 | } 29 | [codes appendFormat:@"\n%@\n",code]; 30 | }]; 31 | NSLog(@"%@",codes); 32 | } 33 | 34 | 35 | #pragma mark - 根据字典key值转模型属性 36 | -(void)wh_createProperty{ 37 | NSMutableString *codes=[NSMutableString string]; 38 | [self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) { 39 | NSString *code; 40 | if ([value isKindOfClass:[NSString class]]) { 41 | code=[NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",key]; 42 | }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){ 43 | code=[NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",key]; 44 | }else if ([value isKindOfClass:[NSNumber class]]) { 45 | code=[NSString stringWithFormat:@"@property (nonatomic, assign) NSInteger %@;",key]; 46 | }else if ([value isKindOfClass:[NSArray class]]) { 47 | code=[NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",key]; 48 | }else if ([value isKindOfClass:[NSDictionary class]]) { 49 | code=[NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",key]; 50 | } 51 | [codes appendFormat:@"\n%@\n",code]; 52 | }]; 53 | NSLog(@"%@",codes); 54 | } 55 | 56 | 57 | + (NSDictionary *)dictionaryByMerging:(NSDictionary *)dict1 with:(NSDictionary *)dict2 58 | { 59 | NSMutableDictionary * result = [NSMutableDictionary dictionaryWithDictionary:dict1]; 60 | NSMutableDictionary * resultTemp = [NSMutableDictionary dictionaryWithDictionary:dict1]; 61 | [resultTemp addEntriesFromDictionary:dict2]; 62 | 63 | [resultTemp enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) { 64 | if ([dict1 objectForKey:key]) 65 | { 66 | if ([obj isKindOfClass:[NSDictionary class]]) 67 | { 68 | NSDictionary * newVal = [[dict1 objectForKey: key] dictionaryByMergingWith: (NSDictionary *) obj]; 69 | [result setObject: newVal forKey: key]; 70 | } 71 | else 72 | { 73 | [result setObject: obj forKey: key]; 74 | } 75 | } 76 | else if([dict2 objectForKey:key]) 77 | { 78 | if ([obj isKindOfClass:[NSDictionary class]]) 79 | { 80 | NSDictionary * newVal = [[dict2 objectForKey: key] dictionaryByMergingWith: (NSDictionary *) obj]; 81 | [result setObject: newVal forKey: key]; 82 | } 83 | else 84 | { 85 | [result setObject: obj forKey: key]; 86 | } 87 | } 88 | }]; 89 | return (NSDictionary *) [result mutableCopy]; 90 | 91 | } 92 | 93 | - (NSDictionary *)dictionaryByMergingWith:(NSDictionary *)dict 94 | { 95 | return [[self class] dictionaryByMerging:self with: dict]; 96 | } 97 | 98 | #pragma mark - Manipulation 99 | - (NSDictionary *)dictionaryByAddingEntriesFromDictionary:(NSDictionary *)dictionary 100 | { 101 | NSMutableDictionary *result = [self mutableCopy]; 102 | [result addEntriesFromDictionary:dictionary]; 103 | return result; 104 | } 105 | 106 | - (NSDictionary *)dictionaryByRemovingEntriesWithKeys:(NSSet *)keys 107 | { 108 | NSMutableDictionary *result = [self mutableCopy]; 109 | [result removeObjectsForKeys:keys.allObjects]; 110 | return result; 111 | } 112 | 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /WHKit/NSFileManager+WHFileManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+WHFileManager.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSFileManager (WHFileManager) 12 | 13 | /** document URL */ 14 | + (NSURL *)documentsURL; 15 | 16 | /** document 路径 */ 17 | + (NSString *)documentsPath; 18 | 19 | /** library URL */ 20 | + (NSURL *)libraryURL; 21 | 22 | /** library 路径 */ 23 | + (NSString *)libraryPath; 24 | 25 | /** cache URL */ 26 | + (NSURL *)cachesURL; 27 | 28 | /** cache 路径 */ 29 | + (NSString *)cachesPath; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /WHKit/NSFileManager+WHFileManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+WHFileManager.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "NSFileManager+WHFileManager.h" 10 | 11 | @implementation NSFileManager (WHFileManager) 12 | 13 | + (NSURL *)URLForDirectory:(NSSearchPathDirectory)directory 14 | { 15 | return [self.defaultManager URLsForDirectory:directory inDomains:NSUserDomainMask].lastObject; 16 | } 17 | 18 | + (NSString *)pathForDirectory:(NSSearchPathDirectory)directory 19 | { 20 | return NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES)[0]; 21 | } 22 | 23 | + (NSURL *)documentsURL 24 | { 25 | return [self URLForDirectory:NSDocumentDirectory]; 26 | } 27 | 28 | + (NSString *)documentsPath 29 | { 30 | return [self pathForDirectory:NSDocumentDirectory]; 31 | } 32 | 33 | + (NSURL *)libraryURL 34 | { 35 | return [self URLForDirectory:NSLibraryDirectory]; 36 | } 37 | 38 | + (NSString *)libraryPath 39 | { 40 | return [self pathForDirectory:NSLibraryDirectory]; 41 | } 42 | 43 | + (NSURL *)cachesURL 44 | { 45 | return [self URLForDirectory:NSCachesDirectory]; 46 | } 47 | 48 | + (NSString *)cachesPath 49 | { 50 | return [self pathForDirectory:NSCachesDirectory]; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /WHKit/NSNumber+WHNumber.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+WHNumber.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSNumber (WHNumber) 12 | 13 | /** 对应的罗马数字 */ 14 | - (NSString *)romanNumeral; 15 | 16 | /** 转换为百分比字符串 */ 17 | - (NSString*)toDisplayPercentageWithDigit:(NSInteger)digit; 18 | 19 | /** 20 | 四舍五入 21 | 22 | @param digit 限制最大位数 23 | @return 四舍五入后的结果 24 | */ 25 | - (NSNumber*)doRoundWithDigit:(NSUInteger)digit; 26 | 27 | /** 28 | 上取整 29 | 30 | @param digit 限制最大位数 31 | @return 上取整后的结果 32 | */ 33 | - (NSNumber*)doCeilWithDigit:(NSUInteger)digit; 34 | 35 | /** 36 | 下取整 37 | 38 | @param digit 限制最大位数 39 | @return 下取整后的结果 40 | */ 41 | - (NSNumber*)doFloorWithDigit:(NSUInteger)digit; 42 | 43 | - (NSString*)toDisplayNumberWithDigit:(NSInteger)digit; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /WHKit/NSNumber+WHNumber.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+WHNumber.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "NSNumber+WHNumber.h" 10 | 11 | @implementation NSNumber (WHNumber) 12 | 13 | - (NSString *)romanNumeral 14 | { 15 | NSInteger n = [self integerValue]; 16 | 17 | NSArray *numerals = [NSArray arrayWithObjects:@"M", @"CM", @"D", @"CD", @"C", @"XC", @"L", @"XL", @"X", @"IX", @"V", @"IV", @"I", nil]; 18 | 19 | NSUInteger valueCount = 13; 20 | NSUInteger values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; 21 | 22 | NSMutableString *numeralString = [NSMutableString string]; 23 | 24 | for (NSUInteger i = 0; i < valueCount; i++) 25 | { 26 | while (n >= values[i]) 27 | { 28 | n -= values[i]; 29 | [numeralString appendString:[numerals objectAtIndex:i]]; 30 | } 31 | } 32 | return numeralString; 33 | } 34 | 35 | 36 | 37 | #pragma mark - Display 38 | - (NSString*)toDisplayNumberWithDigit:(NSInteger)digit 39 | { 40 | NSString *result = nil; 41 | NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 42 | [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; 43 | [formatter setRoundingMode:NSNumberFormatterRoundHalfUp]; 44 | [formatter setMaximumFractionDigits:digit]; 45 | result = [formatter stringFromNumber:self]; 46 | if (result == nil) 47 | return @""; 48 | return result; 49 | 50 | } 51 | 52 | - (NSString*)toDisplayPercentageWithDigit:(NSInteger)digit 53 | { 54 | NSString *result = nil; 55 | NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 56 | [formatter setNumberStyle:NSNumberFormatterPercentStyle]; 57 | [formatter setRoundingMode:NSNumberFormatterRoundHalfUp]; 58 | [formatter setMaximumFractionDigits:digit]; 59 | result = [formatter stringFromNumber:self]; 60 | return result; 61 | } 62 | 63 | #pragma mark - round, ceil, floor 64 | - (NSNumber*)doRoundWithDigit:(NSUInteger)digit 65 | { 66 | NSNumber *result = nil; 67 | NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 68 | [formatter setRoundingMode:NSNumberFormatterRoundHalfUp]; 69 | [formatter setMaximumFractionDigits:digit]; 70 | [formatter setMinimumFractionDigits:digit]; 71 | result = [NSNumber numberWithDouble:[[formatter stringFromNumber:self] doubleValue]]; 72 | return result; 73 | } 74 | 75 | 76 | - (NSNumber*)doCeilWithDigit:(NSUInteger)digit 77 | { 78 | NSNumber *result = nil; 79 | NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 80 | [formatter setRoundingMode:NSNumberFormatterRoundCeiling]; 81 | [formatter setMaximumFractionDigits:digit]; 82 | result = [NSNumber numberWithDouble:[[formatter stringFromNumber:self] doubleValue]]; 83 | return result; 84 | } 85 | 86 | - (NSNumber*)doFloorWithDigit:(NSUInteger)digit 87 | { 88 | NSNumber *result = nil; 89 | NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 90 | [formatter setRoundingMode:NSNumberFormatterRoundFloor]; 91 | [formatter setMaximumFractionDigits:digit]; 92 | result = [NSNumber numberWithDouble:[[formatter stringFromNumber:self] doubleValue]]; 93 | return result; 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /WHKit/NSObject+WHObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+WHObject.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^KVOBlock)(NSDictionary *change, void *context); 12 | 13 | @interface NSObject (WHObject) 14 | 15 | /** 版本号 */ 16 | + (NSString *)version; 17 | 18 | /** build号 */ 19 | + (NSInteger)build; 20 | 21 | /** Bundle id */ 22 | + (NSString *)identifier; 23 | 24 | /** 语言 */ 25 | + (NSString *)currentLanguage; 26 | 27 | /** 架构 */ 28 | + (NSString *)deviceModel; 29 | 30 | /** 类名 */ 31 | - (NSString *)className; 32 | 33 | /** 类名 */ 34 | + (NSString *)className; 35 | 36 | /** 父类名 */ 37 | - (NSString *)superClassName; 38 | 39 | /** 父类名 */ 40 | + (NSString *)superClassName; 41 | 42 | /** 实例属性字典 */ 43 | - (NSDictionary *)propertyDictionary; 44 | 45 | /** 属性名称列表 */ 46 | - (NSArray *)propertyKeys; 47 | 48 | /** 属性名称列表 */ 49 | + (NSArray *)propertyKeys; 50 | 51 | /** 方法列表 */ 52 | - (NSArray *)methodList; 53 | 54 | /** 方法列表 */ 55 | + (NSArray *)methodList; 56 | 57 | /** 格式化方法列表 */ 58 | - (NSArray *)methodListInfo; 59 | 60 | /** 创建并返回一个指向所有已注册类的指针列表 */ 61 | + (NSArray *)registedClassList; 62 | 63 | /** 实例变量 */ 64 | + (NSArray *)instanceVariable; 65 | 66 | /** 是否包含某个属性 */ 67 | - (BOOL)hasPropertyForKey:(NSString*)key; 68 | 69 | /** 是否包含某个实例变量 */ 70 | - (BOOL)hasIvarForKey:(NSString*)key; 71 | 72 | - (void)addObserver:(NSObject *)observer 73 | forKeyPath:(NSString *)keyPath 74 | options:(NSKeyValueObservingOptions)options 75 | context:(void *)context 76 | withBlock:(KVOBlock)block; 77 | 78 | -(void)removeBlockObserver:(NSObject *)observer 79 | forKeyPath:(NSString *)keyPath; 80 | 81 | -(void)addObserverForKeyPath:(NSString *)keyPath 82 | options:(NSKeyValueObservingOptions)options 83 | context:(void *)context 84 | withBlock:(KVOBlock)block; 85 | 86 | -(void)removeBlockObserverForKeyPath:(NSString *)keyPath; 87 | 88 | - (void)modelWithDictionary:(NSDictionary *)dict __attribute__((deprecated(" "))); 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /WHKit/NSObject+WHRuntime.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+WHRuntime.h 3 | // WHRuntimeDemo 4 | // https://github.com/remember17/WHRuntimeDemo 5 | // Created by 吴浩 on 2017/6/20. 6 | // Copyright © 2017年 wuhao. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSObject (WHRuntime) 13 | 14 | /** 属性列表 */ 15 | - (NSArray *)propertiesInfo; 16 | 17 | /** 属性列表 */ 18 | + (NSArray *)propertiesInfo; 19 | 20 | /** 格式化之后的属性列表 */ 21 | + (NSArray *)propertiesWithCodeFormat; 22 | 23 | /** 成员变量列表 */ 24 | - (NSArray *)ivarInfo; 25 | 26 | /** 成员变量列表 */ 27 | + (NSArray *)ivarInfo; 28 | 29 | /** 对象方法列表 */ 30 | -(NSArray*)instanceMethodList; 31 | 32 | /** 对象方法列表 */ 33 | +(NSArray*)instanceMethodList; 34 | 35 | /** 类方法列表 */ 36 | +(NSArray*)classMethodList; 37 | 38 | /** 协议列表 */ 39 | -(NSDictionary *)protocolList; 40 | 41 | /** 协议列表 */ 42 | +(NSDictionary *)protocolList; 43 | 44 | /** 交换实例方法 */ 45 | + (void)SwizzlingInstanceMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod; 46 | 47 | /** 交换类方法 */ 48 | + (void)SwizzlingClassMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod; 49 | 50 | /** 添加方法 */ 51 | + (void)addMethodWithSEL:(SEL)methodSEL methodIMP:(SEL)methodIMP; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /WHKit/NSObject+WHRuntime.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+WHRuntime.m 3 | // WHRuntimeDemo 4 | // https://github.com/remember17/WHRuntimeDemo 5 | // Created by 吴浩 on 2017/6/20. 6 | // Copyright © 2017年 wuhao. All rights reserved. 7 | // 8 | 9 | #import "NSObject+WHRuntime.h" 10 | 11 | @implementation NSObject (WHRuntime) 12 | 13 | - (NSArray *)propertiesInfo 14 | { 15 | return [[self class] propertiesInfo]; 16 | } 17 | 18 | 19 | + (NSArray *)propertiesInfo 20 | { 21 | NSMutableArray *propertieArray = [NSMutableArray array]; 22 | 23 | unsigned int propertyCount; 24 | objc_property_t *properties = class_copyPropertyList([self class], &propertyCount); 25 | 26 | for (int i = 0; i < propertyCount; i++) 27 | { 28 | [propertieArray addObject:({ 29 | 30 | NSDictionary *dictionary = [self dictionaryWithProperty:properties[i]]; 31 | 32 | dictionary; 33 | })]; 34 | } 35 | 36 | free(properties); 37 | 38 | return propertieArray; 39 | } 40 | 41 | 42 | + (NSDictionary *)dictionaryWithProperty:(objc_property_t)property 43 | { 44 | NSMutableDictionary *result = [NSMutableDictionary dictionary]; 45 | 46 | //name 47 | 48 | NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; 49 | [result setObject:propertyName forKey:@"name"]; 50 | 51 | //attribute 52 | 53 | NSMutableDictionary *attributeDictionary = ({ 54 | 55 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 56 | 57 | unsigned int attributeCount; 58 | objc_property_attribute_t *attrs = property_copyAttributeList(property, &attributeCount); 59 | 60 | for (int i = 0; i < attributeCount; i++) 61 | { 62 | NSString *name = [NSString stringWithCString:attrs[i].name encoding:NSUTF8StringEncoding]; 63 | NSString *value = [NSString stringWithCString:attrs[i].value encoding:NSUTF8StringEncoding]; 64 | [dictionary setObject:value forKey:name]; 65 | } 66 | 67 | free(attrs); 68 | 69 | dictionary; 70 | }); 71 | 72 | NSMutableArray *attributeArray = [NSMutableArray array]; 73 | 74 | //R 75 | if ([attributeDictionary objectForKey:@"R"]) 76 | { 77 | [attributeArray addObject:@"readonly"]; 78 | } 79 | //C 80 | if ([attributeDictionary objectForKey:@"C"]) 81 | { 82 | [attributeArray addObject:@"copy"]; 83 | } 84 | //& 85 | if ([attributeDictionary objectForKey:@"&"]) 86 | { 87 | [attributeArray addObject:@"strong"]; 88 | } 89 | //N 90 | if ([attributeDictionary objectForKey:@"N"]) 91 | { 92 | [attributeArray addObject:@"nonatomic"]; 93 | } 94 | else 95 | { 96 | [attributeArray addObject:@"atomic"]; 97 | } 98 | //G 99 | if ([attributeDictionary objectForKey:@"G"]) 100 | { 101 | [attributeArray addObject:[NSString stringWithFormat:@"getter=%@", [attributeDictionary objectForKey:@"G"]]]; 102 | } 103 | //S 104 | if ([attributeDictionary objectForKey:@"S"]) 105 | { 106 | [attributeArray addObject:[NSString stringWithFormat:@"setter=%@", [attributeDictionary objectForKey:@"G"]]]; 107 | } 108 | //D 109 | if ([attributeDictionary objectForKey:@"D"]) 110 | { 111 | [result setObject:[NSNumber numberWithBool:YES] forKey:@"isDynamic"]; 112 | } 113 | else 114 | { 115 | [result setObject:[NSNumber numberWithBool:NO] forKey:@"isDynamic"]; 116 | } 117 | //W 118 | if ([attributeDictionary objectForKey:@"W"]) 119 | { 120 | [attributeArray addObject:@"weak"]; 121 | } 122 | //P 123 | if ([attributeDictionary objectForKey:@"P"]) 124 | { 125 | 126 | } 127 | //T 128 | if ([attributeDictionary objectForKey:@"T"]) 129 | { 130 | 131 | NSDictionary *typeDic = @{@"c":@"char", 132 | @"i":@"int", 133 | @"s":@"short", 134 | @"l":@"long", 135 | @"q":@"long long", 136 | @"C":@"unsigned char", 137 | @"I":@"unsigned int", 138 | @"S":@"unsigned short", 139 | @"L":@"unsigned long", 140 | @"Q":@"unsigned long long", 141 | @"f":@"float", 142 | @"d":@"double", 143 | @"B":@"BOOL", 144 | @"v":@"void", 145 | @"*":@"char *", 146 | @"@":@"id", 147 | @"#":@"Class", 148 | @":":@"SEL", 149 | }; 150 | //TODO:An array 151 | NSString *key = [attributeDictionary objectForKey:@"T"]; 152 | 153 | id type_str = [typeDic objectForKey:key]; 154 | 155 | if (type_str == nil) 156 | { 157 | if ([[key substringToIndex:1] isEqualToString:@"@"] && [key rangeOfString:@"?"].location == NSNotFound) 158 | { 159 | type_str = [[key substringWithRange:NSMakeRange(2, key.length - 3)] stringByAppendingString:@"*"]; 160 | } 161 | else if ([[key substringToIndex:1] isEqualToString:@"^"]) 162 | { 163 | id str = [typeDic objectForKey:[key substringFromIndex:1]]; 164 | 165 | if (str) 166 | { 167 | type_str = [NSString stringWithFormat:@"%@ *",str]; 168 | } 169 | } 170 | else 171 | { 172 | type_str = @"unknow"; 173 | } 174 | } 175 | 176 | [result setObject:type_str forKey:@"type"]; 177 | } 178 | 179 | [result setObject:attributeArray forKey:@"attribute"]; 180 | 181 | return result; 182 | } 183 | 184 | + (NSArray *)propertiesWithCodeFormat 185 | { 186 | NSMutableArray *array = [NSMutableArray array]; 187 | 188 | NSArray *properties = [[self class] propertiesInfo]; 189 | 190 | for (NSDictionary *item in properties) 191 | { 192 | NSMutableString *format = ({ 193 | 194 | NSMutableString *formatString = [NSMutableString stringWithFormat:@"@property "]; 195 | //attribute 196 | NSArray *attribute = [item objectForKey:@"attribute"]; 197 | attribute = [attribute sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 198 | return [obj1 compare:obj2 options:NSNumericSearch]; 199 | }]; 200 | if (attribute && attribute.count > 0) 201 | { 202 | NSString *attributeStr = [NSString stringWithFormat:@"(%@)",[attribute componentsJoinedByString:@", "]]; 203 | 204 | [formatString appendString:attributeStr]; 205 | } 206 | 207 | //type 208 | NSString *type = [item objectForKey:@"type"]; 209 | if (type) { 210 | [formatString appendString:@" "]; 211 | [formatString appendString:type]; 212 | } 213 | 214 | //name 215 | NSString *name = [item objectForKey:@"name"]; 216 | if (name) { 217 | [formatString appendString:@" "]; 218 | [formatString appendString:name]; 219 | [formatString appendString:@";"]; 220 | } 221 | 222 | formatString; 223 | }); 224 | 225 | [array addObject:format]; 226 | } 227 | 228 | return array; 229 | } 230 | 231 | + (NSString *)wh_decodeType:(const char *)cString 232 | { 233 | if (!strcmp(cString, @encode(char))) 234 | return @"char"; 235 | if (!strcmp(cString, @encode(int))) 236 | return @"int"; 237 | if (!strcmp(cString, @encode(short))) 238 | return @"short"; 239 | if (!strcmp(cString, @encode(long))) 240 | return @"long"; 241 | if (!strcmp(cString, @encode(long long))) 242 | return @"long long"; 243 | if (!strcmp(cString, @encode(unsigned char))) 244 | return @"unsigned char"; 245 | if (!strcmp(cString, @encode(unsigned int))) 246 | return @"unsigned int"; 247 | if (!strcmp(cString, @encode(unsigned short))) 248 | return @"unsigned short"; 249 | if (!strcmp(cString, @encode(unsigned long))) 250 | return @"unsigned long"; 251 | if (!strcmp(cString, @encode(unsigned long long))) 252 | return @"unsigned long long"; 253 | if (!strcmp(cString, @encode(float))) 254 | return @"float"; 255 | if (!strcmp(cString, @encode(double))) 256 | return @"double"; 257 | if (!strcmp(cString, @encode(bool))) 258 | return @"bool"; 259 | if (!strcmp(cString, @encode(_Bool))) 260 | return @"_Bool"; 261 | if (!strcmp(cString, @encode(void))) 262 | return @"void"; 263 | if (!strcmp(cString, @encode(char *))) 264 | return @"char *"; 265 | if (!strcmp(cString, @encode(id))) 266 | return @"id"; 267 | if (!strcmp(cString, @encode(Class))) 268 | return @"class"; 269 | if (!strcmp(cString, @encode(SEL))) 270 | return @"SEL"; 271 | if (!strcmp(cString, @encode(BOOL))) 272 | return @"BOOL"; 273 | 274 | NSString *result = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding]; 275 | 276 | if ([[result substringToIndex:1] isEqualToString:@"@"] && [result rangeOfString:@"?"].location == NSNotFound) { 277 | result = [[result substringWithRange:NSMakeRange(2, result.length - 3)] stringByAppendingString:@"*"]; 278 | } else 279 | { 280 | if ([[result substringToIndex:1] isEqualToString:@"^"]) { 281 | result = [NSString stringWithFormat:@"%@ *", 282 | [NSString wh_decodeType:[[result substringFromIndex:1] cStringUsingEncoding:NSUTF8StringEncoding]]]; 283 | } 284 | } 285 | return result; 286 | } 287 | 288 | -(NSArray *)ivarInfo { 289 | return [[self class] ivarInfo]; 290 | } 291 | 292 | + (NSArray *)ivarInfo 293 | { 294 | unsigned int outCount; 295 | Ivar *ivars = class_copyIvarList([self class], &outCount); 296 | NSMutableArray *result = [NSMutableArray array]; 297 | for (int i = 0; i < outCount; i++) { 298 | NSString *type = [[self class] wh_decodeType:ivar_getTypeEncoding(ivars[i])]; 299 | NSString *name = [NSString stringWithCString:ivar_getName(ivars[i]) encoding:NSUTF8StringEncoding]; 300 | NSString *ivarDescription = [NSString stringWithFormat:@"%@ %@", type, name]; 301 | [result addObject:ivarDescription]; 302 | } 303 | free(ivars); 304 | return result.count ? [result copy] : nil; 305 | } 306 | 307 | 308 | -(NSArray*)instanceMethodList 309 | { 310 | u_int count; 311 | NSMutableArray *methodList = [NSMutableArray array]; 312 | Method *methods= class_copyMethodList([self class], &count); 313 | for (int i = 0; i < count ; i++) 314 | { 315 | SEL name = method_getName(methods[i]); 316 | NSString *strName = [NSString stringWithCString:sel_getName(name) encoding:NSUTF8StringEncoding]; 317 | [methodList addObject:strName]; 318 | } 319 | free(methods); 320 | return methodList; 321 | } 322 | 323 | +(NSArray*)instanceMethodList 324 | { 325 | u_int count; 326 | NSMutableArray *methodList = [NSMutableArray array]; 327 | Method * methods= class_copyMethodList([self class], &count); 328 | for (int i = 0; i < count ; i++) 329 | { 330 | SEL name = method_getName(methods[i]); 331 | NSString *strName = [NSString stringWithCString:sel_getName(name) encoding:NSUTF8StringEncoding]; 332 | [methodList addObject:strName]; 333 | } 334 | free(methods); 335 | 336 | return methodList; 337 | } 338 | 339 | 340 | + (NSArray *)classMethodList 341 | { 342 | unsigned int count = 0; 343 | Method *methodList = class_copyMethodList(object_getClass(self), &count); 344 | 345 | NSMutableArray *mutableList = [NSMutableArray arrayWithCapacity:count]; 346 | for (unsigned int i = 0; i < count; i++) 347 | { 348 | Method method = methodList[i]; 349 | SEL methodName = method_getName(method); 350 | [mutableList addObject:NSStringFromSelector(methodName)]; 351 | } 352 | free(methodList); 353 | return [NSArray arrayWithArray:mutableList]; 354 | } 355 | 356 | 357 | -(NSDictionary *)protocolList 358 | { 359 | return [[self class]protocolList]; 360 | } 361 | 362 | + (NSDictionary *)protocolList 363 | { 364 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 365 | 366 | unsigned int count; 367 | Protocol * __unsafe_unretained * protocols = class_copyProtocolList([self class], &count); 368 | for (int i = 0; i < count; i++) 369 | { 370 | Protocol *protocol = protocols[i]; 371 | 372 | NSString *protocolName = [NSString stringWithCString:protocol_getName(protocol) encoding:NSUTF8StringEncoding]; 373 | 374 | NSMutableArray *superProtocolArray = ({ 375 | 376 | NSMutableArray *array = [NSMutableArray array]; 377 | 378 | unsigned int superProtocolCount; 379 | Protocol * __unsafe_unretained * superProtocols = protocol_copyProtocolList(protocol, &superProtocolCount); 380 | for (int ii = 0; ii < superProtocolCount; ii++) 381 | { 382 | Protocol *superProtocol = superProtocols[ii]; 383 | 384 | NSString *superProtocolName = [NSString stringWithCString:protocol_getName(superProtocol) encoding:NSUTF8StringEncoding]; 385 | 386 | [array addObject:superProtocolName]; 387 | } 388 | free(superProtocols); 389 | 390 | array; 391 | }); 392 | 393 | [dictionary setObject:superProtocolArray forKey:protocolName]; 394 | } 395 | free(protocols); 396 | 397 | return dictionary; 398 | } 399 | 400 | 401 | +(void)SwizzlingInstanceMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod { 402 | 403 | Class class = [self class]; 404 | 405 | SEL originalSelector = oldMethod; 406 | SEL swizzledSelector = newMethod; 407 | 408 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 409 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 410 | 411 | BOOL didAddMethod = 412 | class_addMethod(class, 413 | originalSelector, 414 | method_getImplementation(swizzledMethod), 415 | method_getTypeEncoding(swizzledMethod)); 416 | 417 | if (didAddMethod) { 418 | class_replaceMethod(class, 419 | swizzledSelector, 420 | method_getImplementation(originalMethod), 421 | method_getTypeEncoding(originalMethod)); 422 | } else { 423 | method_exchangeImplementations(originalMethod, swizzledMethod); 424 | } 425 | } 426 | 427 | 428 | +(void)SwizzlingClassMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod { 429 | 430 | Class class = object_getClass((id)self); 431 | SEL originalSelector = oldMethod; 432 | SEL swizzledSelector = newMethod; 433 | 434 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 435 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 436 | 437 | BOOL didAddMethod = 438 | class_addMethod(class, 439 | originalSelector, 440 | method_getImplementation(swizzledMethod), 441 | method_getTypeEncoding(swizzledMethod)); 442 | 443 | if (didAddMethod) { 444 | class_replaceMethod(class, 445 | swizzledSelector, 446 | method_getImplementation(originalMethod), 447 | method_getTypeEncoding(originalMethod)); 448 | } else { 449 | method_exchangeImplementations(originalMethod, swizzledMethod); 450 | } 451 | 452 | } 453 | 454 | + (void)addMethodWithSEL:(SEL)methodSEL methodIMP:(SEL)methodIMP { 455 | Method method = class_getInstanceMethod(self, methodIMP); 456 | IMP getMethodIMP = method_getImplementation(method); 457 | const char *types = method_getTypeEncoding(method); 458 | class_addMethod(self, methodSEL, getMethodIMP, types); 459 | } 460 | 461 | @end 462 | -------------------------------------------------------------------------------- /WHKit/NSString+WHString.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+WHString.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSString (WHString) 13 | 14 | /** 15 | 在Document目录下拼接路径 16 | 17 | 例:path = @"test".appendDocumentPath 18 | 19 | @return 拼接好的路径 20 | */ 21 | - (NSString *)appendDocumentPath; 22 | 23 | /** 24 | 在Cache目录下拼接路径 25 | 26 | 例:path = @"test".appendCachePath 27 | 28 | @return 拼接好的路径 29 | */ 30 | - (NSString *)appendCachePath; 31 | 32 | /** 33 | 在Temp目录下拼接路径 34 | 35 | 例:path = @"test".appendTempPath 36 | 37 | @return 拼接好的路径 38 | */ 39 | - (NSString *)appendTempPath; 40 | 41 | /** 42 | 根据左边和右边的字符串,截取中间特定字符串 43 | 44 | @param strLeft 左边匹配字符串 45 | @param strRight 右边匹配的字符串 46 | @return 目标字符串 47 | */ 48 | - (NSString*)wh_substringWithinBoundsLeft:(NSString*)strLeft right:(NSString*)strRight; 49 | 50 | /** 51 | 阿拉伯数字转成中文 52 | 53 | @param arebic 阿拉伯数字 54 | @return 返回的中文数字 55 | */ 56 | +(NSString *)wh_translation:(NSString *)arebic; 57 | 58 | /** 59 | 字符串反转 60 | 61 | @param str 要反转的字符串 62 | @return 反转之后的字符串 63 | */ 64 | - (NSString*)wh_reverseWordsInString:(NSString*)str; 65 | 66 | /** 67 | 获得汉字的拼音 68 | 69 | @param chinese 汉字 70 | @return 拼音 71 | */ 72 | + (NSString *)wh_transform:(NSString *)chinese; 73 | 74 | /** 判断URL中是否包含中文 */ 75 | - (BOOL)isContainChinese; 76 | 77 | /** 获取字符数量 */ 78 | - (int)wordsCount; 79 | 80 | /** JSON字符串转成NSDictionary */ 81 | -(NSDictionary *)dictionaryValue; 82 | 83 | /** 手机号码的有效性:分电信、联通、移动和小灵通 */ 84 | - (BOOL)isMobileNumberClassification; 85 | 86 | /** 手机号有效性 */ 87 | - (BOOL)isMobileNumber; 88 | 89 | /**邮箱的有效性 */ 90 | - (BOOL)isEmailAddress; 91 | 92 | /** 简单的身份证有效性 */ 93 | - (BOOL)simpleVerifyIdentityCardNum; 94 | 95 | /** 96 | 精确身份证有效验证 97 | 98 | @param value 目标身份证 99 | @return 是否有效 100 | */ 101 | + (BOOL)accurateVerifyIDCardNumber:(NSString *)value; 102 | 103 | /** 车牌号的有效性 */ 104 | - (BOOL)isCarNumber; 105 | 106 | /** 银行卡的有效性 */ 107 | - (BOOL)bankCardluhmCheck; 108 | 109 | /** IP地址有效性 */ 110 | - (BOOL)isIPAddress; 111 | 112 | /** Mac地址有效性 */ 113 | - (BOOL)isMacAddress; 114 | 115 | /** 网址有效性 */ 116 | - (BOOL)isValidUrl; 117 | 118 | /** 是否纯汉字 */ 119 | - (BOOL)isValidChinese; 120 | 121 | /** 邮政编码 */ 122 | - (BOOL)isValidPostalcode; 123 | 124 | /** 工商税号 */ 125 | - (BOOL)isValidTaxNo; 126 | 127 | /** 清除html标签 */ 128 | - (NSString *)stringByStrippingHTML; 129 | 130 | /** 清除js脚本 */ 131 | - (NSString *)stringByRemovingScriptsAndStrippingHTML; 132 | 133 | /** 去除空格 */ 134 | - (NSString *)trimmingWhitespace; 135 | 136 | /** 去除空格与空行 */ 137 | - (NSString *)trimmingWhitespaceAndNewlines; 138 | 139 | /** 字符串转为Data */ 140 | - (NSData *)toData; 141 | 142 | /** Data转为字符串 */ 143 | + (NSString *)toStringWithData:(NSData *)data; 144 | 145 | - (NSString *)toMD5; 146 | - (NSString *)to16MD5; 147 | - (NSString *)sha1; 148 | - (NSString *)sha256; 149 | - (NSString *)sha512; 150 | 151 | @end 152 | 153 | 154 | /** 155 | * 正则表达式简单说明 156 | * 语法: 157 | . 匹配除换行符以外的任意字符 158 | \w 匹配字母或数字或下划线或汉字 159 | \s 匹配任意的空白符 160 | \d 匹配数字 161 | \b 匹配单词的开始或结束 162 | ^ 匹配字符串的开始 163 | $ 匹配字符串的结束 164 | * 重复零次或更多次 165 | + 重复一次或更多次 166 | ? 重复零次或一次 167 | {n} 重复n次 168 | {n,} 重复n次或更多次 169 | {n,m} 重复n到m次 170 | \W 匹配任意不是字母,数字,下划线,汉字的字符 171 | \S 匹配任意不是空白符的字符 172 | \D 匹配任意非数字的字符 173 | \B 匹配不是单词开头或结束的位置 174 | [^x] 匹配除了x以外的任意字符 175 | [^aeiou]匹配除了aeiou这几个字母以外的任意字符 176 | *? 重复任意次,但尽可能少重复 177 | +? 重复1次或更多次,但尽可能少重复 178 | ?? 重复0次或1次,但尽可能少重复 179 | {n,m}? 重复n到m次,但尽可能少重复 180 | {n,}? 重复n次以上,但尽可能少重复 181 | \a 报警字符(打印它的效果是电脑嘀一声) 182 | \b 通常是单词分界位置,但如果在字符类里使用代表退格 183 | \t 制表符,Tab 184 | \r 回车 185 | \v 竖向制表符 186 | \f 换页符 187 | \n 换行符 188 | \e Escape 189 | \0nn ASCII代码中八进制代码为nn的字符 190 | \xnn ASCII代码中十六进制代码为nn的字符 191 | \unnnn Unicode代码中十六进制代码为nnnn的字符 192 | \cN ASCII控制字符。比如\cC代表Ctrl+C 193 | \A 字符串开头(类似^,但不受处理多行选项的影响) 194 | \Z 字符串结尾或行尾(不受处理多行选项的影响) 195 | \z 字符串结尾(类似$,但不受处理多行选项的影响) 196 | \G 当前搜索的开头 197 | \p{name} Unicode中命名为name的字符类,例如\p{IsGreek} 198 | (?>exp) 贪婪子表达式 199 | (?-exp) 平衡组 200 | (?im-nsx:exp) 在子表达式exp中改变处理选项 201 | (?im-nsx) 为表达式后面的部分改变处理选项 202 | (?(exp)yes|no) 把exp当作零宽正向先行断言,如果在这个位置能匹配,使用yes作为此组的表达式;否则使用no 203 | (?(exp)yes) 同上,只是使用空表达式作为no 204 | (?(name)yes|no) 如果命名为name的组捕获到了内容,使用yes作为表达式;否则使用no 205 | (?(name)yes) 同上,只是使用空表达式作为no 206 | 207 | 捕获 208 | (exp) 匹配exp,并捕获文本到自动命名的组里 209 | (?exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?'name'exp) 210 | (?:exp) 匹配exp,不捕获匹配的文本,也不给此分组分配组号 211 | 零宽断言 212 | (?=exp) 匹配exp前面的位置 213 | (?<=exp) 匹配exp后面的位置 214 | (?!exp) 匹配后面跟的不是exp的位置 215 | (? 10 | 11 | typedef void(^TimerCallback)(NSTimer *timer); 12 | 13 | @interface NSTimer (WHTimer) 14 | 15 | /** 16 | 定时事件,自定义是否重复 17 | 18 | @param interval 时间间隔 19 | @param repeats 是否重复 20 | @param callback 回调 21 | @return timer 22 | */ 23 | + (NSTimer *)wh_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 24 | repeats:(BOOL)repeats 25 | callback:(TimerCallback)callback; 26 | 27 | /** 28 | 定时事件,自定义重复次数 29 | 30 | @param interval 时间间隔 31 | @param count 重复次数 32 | @param callback 回调 33 | @return timer 34 | */ 35 | + (NSTimer *)wh_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 36 | count:(NSInteger)count 37 | callback:(TimerCallback)callback; 38 | 39 | /** 暂停timer */ 40 | - (void)pauseTimer; 41 | 42 | /** 开始timer */ 43 | - (void)resumeTimer; 44 | 45 | /** 延迟开始timer */ 46 | - (void)resumeTimerAfterTimeInterval:(NSTimeInterval)interval; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /WHKit/NSTimer+WHTimer.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSTimer+WHTimer.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "NSTimer+WHTimer.h" 10 | #import 11 | 12 | static const void *timer_private_currentCountTime = "timer_private_currentCountTime"; 13 | 14 | @implementation NSTimer (WHTimer) 15 | 16 | - (NSNumber *)timer_private_currentCountTime { 17 | NSNumber *obj = objc_getAssociatedObject(self, timer_private_currentCountTime); 18 | 19 | if (obj == nil) { 20 | obj = @(0); 21 | 22 | [self settimer_private_currentCountTime:obj]; 23 | } 24 | 25 | return obj; 26 | } 27 | 28 | - (void)settimer_private_currentCountTime:(NSNumber *)time { 29 | objc_setAssociatedObject(self, 30 | timer_private_currentCountTime, 31 | time, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 32 | } 33 | 34 | + (NSTimer *)wh_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 35 | count:(NSInteger)count 36 | callback:(TimerCallback)callback { 37 | if (count <= 0) { 38 | return [self wh_scheduledTimerWithTimeInterval:interval 39 | repeats:YES 40 | callback:callback]; 41 | } 42 | 43 | NSDictionary *userInfo = @{@"callback" : callback, 44 | @"count" : @(count)}; 45 | return [NSTimer scheduledTimerWithTimeInterval:interval 46 | target:self 47 | selector:@selector(timer_onTimerUpdateCountBlock:) 48 | userInfo:userInfo 49 | repeats:YES]; 50 | } 51 | 52 | + (NSTimer *)wh_scheduledTimerWithTimeInterval:(NSTimeInterval)interval 53 | repeats:(BOOL)repeats 54 | callback:(TimerCallback)callback { 55 | return [NSTimer scheduledTimerWithTimeInterval:interval 56 | target:self 57 | selector:@selector(timer_onTimerUpdateBlock:) 58 | userInfo:callback 59 | repeats:repeats]; 60 | } 61 | 62 | - (void)timer_fireTimer { 63 | [self setFireDate:[NSDate distantPast]]; 64 | } 65 | 66 | - (void)timer_unfireTimer { 67 | [self setFireDate:[NSDate distantFuture]]; 68 | } 69 | 70 | - (void)timer_invalidate { 71 | if (self.isValid) { 72 | [self invalidate]; 73 | } 74 | } 75 | 76 | #pragma mark - Private 77 | + (void)timer_onTimerUpdateBlock:(NSTimer *)timer { 78 | TimerCallback block = timer.userInfo; 79 | 80 | if (block) { 81 | block(timer); 82 | } 83 | } 84 | 85 | + (void)timer_onTimerUpdateCountBlock:(NSTimer *)timer { 86 | NSInteger currentCount = [[timer timer_private_currentCountTime] integerValue]; 87 | 88 | NSDictionary *userInfo = timer.userInfo; 89 | TimerCallback callback = userInfo[@"callback"]; 90 | NSNumber *count = userInfo[@"count"]; 91 | 92 | if (currentCount < count.integerValue) { 93 | currentCount++; 94 | [timer settimer_private_currentCountTime:@(currentCount)]; 95 | 96 | if (callback) { 97 | callback(timer); 98 | } 99 | } else { 100 | currentCount = 0; 101 | [timer settimer_private_currentCountTime:@(currentCount)]; 102 | 103 | [timer timer_unfireTimer]; 104 | [timer timer_invalidate]; 105 | } 106 | } 107 | 108 | -(void)pauseTimer 109 | { 110 | if (![self isValid]) 111 | { 112 | return ; 113 | } 114 | 115 | [self setFireDate:[NSDate distantFuture]]; 116 | } 117 | 118 | -(void)resumeTimer 119 | { 120 | if (![self isValid]) 121 | { 122 | return ; 123 | } 124 | 125 | [self setFireDate:[NSDate date]]; 126 | } 127 | 128 | - (void)resumeTimerAfterTimeInterval:(NSTimeInterval)interval 129 | { 130 | if (![self isValid]) 131 | { 132 | return ; 133 | } 134 | 135 | [self setFireDate:[NSDate dateWithTimeIntervalSinceNow:interval]]; 136 | } 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /WHKit/SerializeKit.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // https://github.com/remember17 4 | 5 | #ifndef SerializeKit_h 6 | #define SerializeKit_h 7 | #import 8 | 9 | #define kSerialize_Coder_Decoder() \ 10 | \ 11 | - (id)initWithCoder:(NSCoder *)coder \ 12 | { \ 13 | NSLog(@"%s",__func__); \ 14 | Class cls = [self class]; \ 15 | while (cls != [NSObject class]) { \ 16 | \ 17 | BOOL bIsSelfClass = (cls == [self class]); \ 18 | unsigned int iVarCount = 0; \ 19 | unsigned int propVarCount = 0; \ 20 | unsigned int sharedVarCount = 0; \ 21 | Ivar *ivarList = bIsSelfClass ? class_copyIvarList([cls class], &iVarCount) : NULL; \ 22 | objc_property_t *propList = bIsSelfClass ? NULL : class_copyPropertyList(cls, &propVarCount); \ 23 | sharedVarCount = bIsSelfClass ? iVarCount : propVarCount; \ 24 | \ 25 | for (int i = 0; i < sharedVarCount; i++) { \ 26 | const char *varName = bIsSelfClass ? ivar_getName(*(ivarList + i)) : property_getName(*(propList + i)); \ 27 | NSString *key = [NSString stringWithUTF8String:varName]; \ 28 | id varValue = [coder decodeObjectForKey:key]; \ 29 | NSArray *filters = @[@"superclass", @"description", @"debugDescription", @"hash"]; \ 30 | if (varValue && [filters containsObject:key] == NO) { \ 31 | [self setValue:varValue forKey:key]; \ 32 | } \ 33 | } \ 34 | free(ivarList); \ 35 | free(propList); \ 36 | cls = class_getSuperclass(cls); \ 37 | } \ 38 | return self; \ 39 | } \ 40 | \ 41 | - (void)encodeWithCoder:(NSCoder *)coder \ 42 | { \ 43 | NSLog(@"%s",__func__); \ 44 | Class cls = [self class]; \ 45 | while (cls != [NSObject class]) { \ 46 | \ 47 | BOOL bIsSelfClass = (cls == [self class]); \ 48 | unsigned int iVarCount = 0; \ 49 | unsigned int propVarCount = 0; \ 50 | unsigned int sharedVarCount = 0; \ 51 | Ivar *ivarList = bIsSelfClass ? class_copyIvarList([cls class], &iVarCount) : NULL; \ 52 | objc_property_t *propList = bIsSelfClass ? NULL : class_copyPropertyList(cls, &propVarCount); \ 53 | sharedVarCount = bIsSelfClass ? iVarCount : propVarCount; \ 54 | \ 55 | for (int i = 0; i < sharedVarCount; i++) { \ 56 | const char *varName = bIsSelfClass ? ivar_getName(*(ivarList + i)) : property_getName(*(propList + i)); \ 57 | NSString *key = [NSString stringWithUTF8String:varName]; \ 58 | \ 59 | id varValue = [self valueForKey:key]; \ 60 | NSArray *filters = @[@"superclass", @"description", @"debugDescription", @"hash"]; \ 61 | if (varValue && [filters containsObject:key] == NO) { \ 62 | [coder encodeObject:varValue forKey:key]; \ 63 | } \ 64 | } \ 65 | free(ivarList); \ 66 | free(propList); \ 67 | cls = class_getSuperclass(cls); \ 68 | } \ 69 | } 70 | 71 | 72 | #define kSerialize_Copy_With_Zone() \ 73 | \ 74 | \ 75 | - (id)copyWithZone:(NSZone *)zone \ 76 | { \ 77 | NSLog(@"%s",__func__); \ 78 | id copy = [[[self class] allocWithZone:zone] init]; \ 79 | Class cls = [self class]; \ 80 | while (cls != [NSObject class]) { \ 81 | \ 82 | BOOL bIsSelfClass = (cls == [self class]); \ 83 | unsigned int iVarCount = 0; \ 84 | unsigned int propVarCount = 0; \ 85 | unsigned int sharedVarCount = 0; \ 86 | Ivar *ivarList = bIsSelfClass ? class_copyIvarList([cls class], &iVarCount) : NULL; \ 87 | objc_property_t *propList = bIsSelfClass ? NULL : class_copyPropertyList(cls, &propVarCount); \ 88 | sharedVarCount = bIsSelfClass ? iVarCount : propVarCount; \ 89 | \ 90 | for (int i = 0; i < sharedVarCount; i++) { \ 91 | const char *varName = bIsSelfClass ? ivar_getName(*(ivarList + i)) : property_getName(*(propList + i)); \ 92 | NSString *key = [NSString stringWithUTF8String:varName]; \ 93 | \ 94 | id varValue = [self valueForKey:key]; \ 95 | NSArray *filters = @[@"superclass", @"description", @"debugDescription", @"hash"]; \ 96 | if (varValue && [filters containsObject:key] == NO) { \ 97 | [copy setValue:varValue forKey:key]; \ 98 | } \ 99 | } \ 100 | free(ivarList); \ 101 | free(propList); \ 102 | cls = class_getSuperclass(cls); \ 103 | } \ 104 | return copy; \ 105 | } 106 | 107 | 108 | #define kSerialize_Description() \ 109 | \ 110 | \ 111 | - (NSString *)description \ 112 | { \ 113 | NSString *despStr = @""; \ 114 | Class cls = [self class]; \ 115 | while (cls != [NSObject class]) { \ 116 | \ 117 | BOOL bIsSelfClass = (cls == [self class]); \ 118 | unsigned int iVarCount = 0; \ 119 | unsigned int propVarCount = 0; \ 120 | unsigned int sharedVarCount = 0; \ 121 | Ivar *ivarList = bIsSelfClass ? class_copyIvarList([cls class], &iVarCount) : NULL; \ 122 | objc_property_t *propList = bIsSelfClass ? NULL : class_copyPropertyList(cls, &propVarCount); \ 123 | sharedVarCount = bIsSelfClass ? iVarCount : propVarCount; \ 124 | \ 125 | for (int i = 0; i < sharedVarCount; i++) { \ 126 | const char *varName = bIsSelfClass ? ivar_getName(*(ivarList + i)) : property_getName(*(propList + i)); \ 127 | NSString *key = [NSString stringWithUTF8String:varName]; \ 128 | \ 129 | id varValue = [self valueForKey:key]; \ 130 | NSArray *filters = @[@"superclass", @"description", @"debugDescription", @"hash"]; \ 131 | if (varValue && [filters containsObject:key] == NO) { \ 132 | despStr = [despStr stringByAppendingString:[NSString stringWithFormat:@"%@: %@\n", key, varValue]]; \ 133 | } \ 134 | } \ 135 | free(ivarList); \ 136 | free(propList); \ 137 | cls = class_getSuperclass(cls); \ 138 | } \ 139 | return despStr; \ 140 | } 141 | 142 | /* 归档 */ 143 | #define kSerialize_Archive(__objToBeArchived__, __key__, __filePath__) \ 144 | \ 145 | NSMutableData *data = [NSMutableData data]; \ 146 | NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; \ 147 | [archiver encodeObject:__objToBeArchived__ forKey:__key__]; \ 148 | [archiver finishEncoding]; \ 149 | [data writeToFile:__filePath__ atomically:YES] 150 | 151 | 152 | /* 解归档 */ 153 | #define kSerialize_Unarchive(__objToStoreData__, __key__, __filePath__) \ 154 | NSMutableData *dedata = [NSMutableData dataWithContentsOfFile:__filePath__]; \ 155 | NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:dedata]; \ 156 | __objToStoreData__ = [unarchiver decodeObjectForKey:__key__]; \ 157 | [unarchiver finishDecoding] 158 | 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /WHKit/UIAlertController+WHAlert.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertController+WHAlert.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/7/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, OptionStyle) { 12 | OptionStyleStyleOK_Cancel = 0, 13 | OptionStyleStyleOnlyOK 14 | }; 15 | 16 | @interface UIAlertController (WHAlert) 17 | 18 | /** 19 | 中间弹窗 20 | 21 | @param title 标题 22 | @param message 消息 23 | @param optionStyle 弹窗选项样式,两个选择或只有一个 24 | @param okTitle 右边选项的文字 25 | @param cancelTitle 左边选项的文字 26 | @param okBlock 右边选择选中后执行的代码 27 | @param cancelBlock 左边选项选中后执行的代码 28 | @return UIAlertController 29 | */ 30 | + (UIAlertController *)wh_alertControllerWithTitle:(NSString *)title message:(NSString *)message optionStyle:(OptionStyle)optionStyle OkTitle:(NSString *)okTitle cancelTitle:(NSString *)cancelTitle okBlock:(dispatch_block_t)okBlock cancelBlock:(dispatch_block_t)cancelBlock; 31 | 32 | 33 | /** 34 | 从下面出现的弹窗 35 | 36 | @param title 标题 37 | @param message 消息 38 | @param optionStyle 弹窗选项样式,两个选择或只有一个 39 | @param okTitle 上面选项的文字 40 | @param cancelTitle 下面选项的文字 41 | @param okBlock 上面选择选中后执行的代码 42 | @param cancelBlock 下面选项选中后执行的代码 43 | @return UIAlertController 44 | */ 45 | + (UIAlertController *)wh_sheetAlertControllerWithTitle:(NSString *)title message:(NSString *)message optionStyle:(OptionStyle)optionStyle OkTitle:(NSString *)okTitle cancelTitle:(NSString *)cancelTitle okBlock:(dispatch_block_t)okBlock cancelBlock:(dispatch_block_t)cancelBlock; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /WHKit/UIAlertController+WHAlert.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertController+WHAlert.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/7/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIAlertController+WHAlert.h" 10 | 11 | @implementation UIAlertController (WHAlert) 12 | 13 | + (UIAlertController *)wh_alertControllerWithTitle:(NSString *)title message:(NSString *)message optionStyle:(OptionStyle)optionStyle OkTitle:(NSString *)okTitle cancelTitle:(NSString *)cancelTitle okBlock:(dispatch_block_t)okBlock cancelBlock:(dispatch_block_t)cancelBlock{ 14 | 15 | UIAlertController* alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; 16 | if (optionStyle == OptionStyleStyleOnlyOK) { 17 | UIAlertAction* OK=[UIAlertAction actionWithTitle:okTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 18 | if (okBlock) { 19 | okBlock(); 20 | } 21 | }]; 22 | [alert addAction:OK]; 23 | } else { 24 | UIAlertAction* cancel=[UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 25 | if (cancelBlock) { 26 | cancelBlock(); 27 | } 28 | }]; 29 | UIAlertAction* OK=[UIAlertAction actionWithTitle:okTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 30 | if (okBlock) { 31 | okBlock(); 32 | } 33 | }]; 34 | [alert addAction:cancel]; 35 | [alert addAction:OK]; 36 | } 37 | return alert; 38 | } 39 | 40 | 41 | + (UIAlertController *)wh_sheetAlertControllerWithTitle:(NSString *)title message:(NSString *)message optionStyle:(OptionStyle)optionStyle OkTitle:(NSString *)okTitle cancelTitle:(NSString *)cancelTitle okBlock:(dispatch_block_t)okBlock cancelBlock:(dispatch_block_t)cancelBlock { 42 | 43 | UIAlertController* alert=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; 44 | if (optionStyle == OptionStyleStyleOnlyOK) { 45 | UIAlertAction* OK=[UIAlertAction actionWithTitle:okTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 46 | if (okBlock) { 47 | okBlock(); 48 | } 49 | }]; 50 | [alert addAction:OK]; 51 | } else { 52 | UIAlertAction* cancel=[UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 53 | if (cancelBlock) { 54 | cancelBlock(); 55 | } 56 | }]; 57 | UIAlertAction* OK=[UIAlertAction actionWithTitle:okTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 58 | if (okBlock) { 59 | okBlock(); 60 | } 61 | }]; 62 | [alert addAction:cancel]; 63 | [alert addAction:OK]; 64 | } 65 | return alert; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /WHKit/UIBarButtonItem+WHBarButtonItem.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+WHBarButtonItem.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIBarButtonItem (WHBarButtonItem) 12 | 13 | /** 快速创建导航栏按钮 */ 14 | +(instancetype _Nullable )wh_barButtonItemWithTitle:(NSString *_Nullable)title 15 | imageName:(NSString *_Nullable)imageName 16 | target:(nullable id)target 17 | action:(nonnull SEL)action 18 | fontSize:(CGFloat)fontSize 19 | titleNormalColor:(UIColor *_Nullable)normalColor 20 | titleHighlightedColor:(UIColor *_Nullable)highlightedColor; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /WHKit/UIBarButtonItem+WHBarButtonItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+WHBarButtonItem.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIBarButtonItem+WHBarButtonItem.h" 10 | 11 | @implementation UIBarButtonItem (WHBarButtonItem) 12 | 13 | +(instancetype _Nullable )wh_barButtonItemWithTitle:(NSString *_Nullable)title imageName:(NSString *_Nullable)imageName target:(nullable id)target action:(nonnull SEL)action fontSize:(CGFloat)fontSize titleNormalColor:(UIColor *_Nullable)normalColor titleHighlightedColor:(UIColor *_Nullable)highlightedColor { 14 | 15 | UIButton *button = [UIButton new]; 16 | [button setTitle:title forState:UIControlStateNormal]; 17 | [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]; 18 | [button setTitleColor:normalColor forState:UIControlStateNormal]; 19 | [button setTitleColor:highlightedColor forState:UIControlStateHighlighted]; 20 | button.titleLabel.font = [UIFont systemFontOfSize:fontSize]; 21 | [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 22 | [button sizeToFit]; 23 | return [[UIBarButtonItem alloc] initWithCustomView:button]; 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /WHKit/UIButton+WHButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+WHButton.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^TouchedButtonBlock)(void); 12 | 13 | @interface UIButton (WHButton) 14 | 15 | /** 快速创建按钮 */ 16 | +(instancetype)wh_buttonWithTitle:(NSString *)title 17 | backColor:(UIColor *)backColor 18 | backImageName:(NSString *)backImageName 19 | titleColor:(UIColor *)color 20 | fontSize:(int)fontSize 21 | frame:(CGRect)frame 22 | cornerRadius:(CGFloat)cornerRadius; 23 | 24 | /** 25 | 多久之后开始执行 26 | 27 | @param timeout 多少秒 28 | @param waitBlock 倒计时 29 | @param finishBlock 倒计时结束时回调 30 | */ 31 | - (void)startTime:(NSInteger)timeout waitBlock:(void(^)(NSInteger remainTime))waitBlock finishBlock:(void(^)(void))finishBlock; 32 | 33 | /** 触发按钮点击事件 */ 34 | - (void)wh_addActionHandler:(TouchedButtonBlock)touchHandler; 35 | 36 | /** 显示菊花 */ 37 | - (void)wh_showIndicator; 38 | 39 | /** 隐藏菊花 */ 40 | - (void)wh_hideIndicator; 41 | 42 | /** 改变按钮的响应区域,上左下右分别增加或减小多少 正数为增加 负数为减小 */ 43 | @property (nonatomic, assign) UIEdgeInsets clickEdgeInsets; 44 | 45 | /** 角标 */ 46 | @property (strong, nonatomic) UILabel *badge; 47 | 48 | /** 角标的值 */ 49 | @property (nonatomic) NSString *badgeValue; 50 | 51 | /** 角标背景颜色 */ 52 | @property (nonatomic) UIColor *badgeBGColor; 53 | 54 | /** 角标文字颜色 */ 55 | @property (nonatomic) UIColor *badgeTextColor; 56 | 57 | /** 角标文字的字体 */ 58 | @property (nonatomic) UIFont *badgeFont; 59 | 60 | /** 角标边距 */ 61 | @property (nonatomic) CGFloat badgePadding; 62 | 63 | /** 角标最小的大小 */ 64 | @property (nonatomic) CGFloat badgeMinSize; 65 | 66 | /** 角标x坐标 */ 67 | @property (nonatomic) CGFloat badgeOriginX; 68 | 69 | /** 角标y坐标 */ 70 | @property (nonatomic) CGFloat badgeOriginY; 71 | 72 | /** 如果是数字0的话就隐藏角标不显示 */ 73 | @property BOOL shouldHideBadgeAtZero; 74 | 75 | /** 显示角标是否要缩放动画 */ 76 | @property BOOL shouldAnimateBadge; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /WHKit/UIButton+WHButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+WHButton.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIButton+WHButton.h" 10 | #import 11 | 12 | static NSString *const IndicatorViewKey = @"indicatorView"; 13 | static NSString *const ButtonTextObjectKey = @"buttonTextObject"; 14 | 15 | NSString const *UIButton_badgeKey = @"UIButton_badgeKey"; 16 | NSString const *UIButton_badgeBGColorKey = @"UIButton_badgeBGColorKey"; 17 | NSString const *UIButton_badgeTextColorKey = @"UIButton_badgeTextColorKey"; 18 | NSString const *UIButton_badgeFontKey = @"UIButton_badgeFontKey"; 19 | NSString const *UIButton_badgePaddingKey = @"UIButton_badgePaddingKey"; 20 | NSString const *UIButton_badgeMinSizeKey = @"UIButton_badgeMinSizeKey"; 21 | NSString const *UIButton_badgeOriginXKey = @"UIButton_badgeOriginXKey"; 22 | NSString const *UIButton_badgeOriginYKey = @"UIButton_badgeOriginYKey"; 23 | NSString const *UIButton_shouldHideBadgeAtZeroKey = @"UIButton_shouldHideBadgeAtZeroKey"; 24 | NSString const *UIButton_shouldAnimateBadgeKey = @"UIButton_shouldAnimateBadgeKey"; 25 | NSString const *UIButton_badgeValueKey = @"UIButton_badgeValueKey"; 26 | 27 | 28 | @implementation UIButton (WHButton) 29 | 30 | @dynamic badgeValue, badgeBGColor, badgeTextColor, badgeFont; 31 | @dynamic badgePadding, badgeMinSize, badgeOriginX, badgeOriginY; 32 | @dynamic shouldHideBadgeAtZero, shouldAnimateBadge; 33 | 34 | +(instancetype)wh_buttonWithTitle:(NSString *)title backColor:(UIColor *)backColor backImageName:(NSString *)backImageName titleColor:(UIColor *)color fontSize:(int)fontSize frame:(CGRect)frame cornerRadius:(CGFloat)cornerRadius { 35 | 36 | UIButton *button = [UIButton new]; 37 | [button setTitle:title forState:UIControlStateNormal]; 38 | [button setBackgroundColor:backColor]; 39 | [button setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal]; 40 | [button setTitleColor:color forState:UIControlStateNormal]; 41 | button.titleLabel.font = [UIFont systemFontOfSize:fontSize]; 42 | [button sizeToFit]; 43 | button.frame=frame; 44 | button.layer.cornerRadius=cornerRadius; 45 | button.clipsToBounds=YES; 46 | return button; 47 | } 48 | 49 | 50 | 51 | - (void)startTime:(NSInteger)timeout waitBlock:(void(^)(NSInteger remainTime))waitBlock finishBlock:(void(^)(void))finishBlock; 52 | { 53 | __block NSInteger timeOut = timeout; 54 | 55 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 56 | dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); 57 | dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行 58 | 59 | dispatch_source_set_event_handler(_timer, ^{ 60 | 61 | if(timeOut <= 0) 62 | { 63 | dispatch_source_cancel(_timer); 64 | dispatch_async(dispatch_get_main_queue(), ^{ 65 | if (finishBlock) 66 | { 67 | finishBlock(); 68 | } 69 | self.userInteractionEnabled = YES; 70 | }); 71 | } 72 | else 73 | { 74 | dispatch_async(dispatch_get_main_queue(), ^{ 75 | if (waitBlock) 76 | { 77 | waitBlock(timeOut); 78 | } 79 | self.userInteractionEnabled = NO; 80 | }); 81 | timeOut--; 82 | } 83 | }); 84 | dispatch_resume(_timer); 85 | } 86 | 87 | 88 | - (void)wh_addActionHandler:(TouchedButtonBlock)touchHandler 89 | { 90 | objc_setAssociatedObject(self, @selector(wh_addActionHandler:), touchHandler, OBJC_ASSOCIATION_COPY_NONATOMIC); 91 | [self addTarget:self action:@selector(blockActionTouched:) forControlEvents:UIControlEventTouchUpInside]; 92 | } 93 | 94 | - (void)blockActionTouched:(UIButton *)btn 95 | { 96 | TouchedButtonBlock block = objc_getAssociatedObject(self, @selector(wh_addActionHandler:)); 97 | if (block) 98 | { 99 | block(); 100 | } 101 | } 102 | 103 | 104 | 105 | - (void)wh_showIndicator 106 | { 107 | UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 108 | indicator.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); 109 | [indicator startAnimating]; 110 | 111 | NSString *currentButtonText = self.titleLabel.text; 112 | 113 | objc_setAssociatedObject(self, &ButtonTextObjectKey, currentButtonText, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 114 | objc_setAssociatedObject(self, &IndicatorViewKey, indicator, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 115 | 116 | self.enabled = NO; 117 | [self setTitle:@"" forState:UIControlStateNormal]; 118 | [self addSubview:indicator]; 119 | } 120 | 121 | - (void)wh_hideIndicator 122 | { 123 | NSString *currentButtonText = (NSString *)objc_getAssociatedObject(self, &ButtonTextObjectKey); 124 | UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)objc_getAssociatedObject(self, &IndicatorViewKey); 125 | 126 | self.enabled = YES; 127 | [indicator removeFromSuperview]; 128 | [self setTitle:currentButtonText forState:UIControlStateNormal]; 129 | } 130 | 131 | 132 | - (void)badgeInit 133 | { 134 | self.badgeBGColor = [UIColor redColor]; 135 | self.badgeTextColor = [UIColor whiteColor]; 136 | self.badgeFont = [UIFont systemFontOfSize:9.0]; 137 | self.badgePadding = 5; 138 | self.badgeMinSize = 4; 139 | self.badgeOriginX = self.frame.size.width - self.badge.frame.size.width/2-3; 140 | self.badgeOriginY = -6; 141 | self.shouldHideBadgeAtZero = YES; 142 | self.shouldAnimateBadge = YES; 143 | self.clipsToBounds = NO; 144 | } 145 | 146 | #pragma mark - Utility methods 147 | 148 | - (void)refreshBadge 149 | { 150 | self.badge.textColor = self.badgeTextColor; 151 | self.badge.backgroundColor = self.badgeBGColor; 152 | self.badge.font = self.badgeFont; 153 | } 154 | 155 | - (CGSize) badgeExpectedSize 156 | { 157 | UILabel *frameLabel = [self duplicateLabel:self.badge]; 158 | [frameLabel sizeToFit]; 159 | 160 | CGSize expectedLabelSize = frameLabel.frame.size; 161 | return expectedLabelSize; 162 | } 163 | 164 | - (void)updateBadgeFrame 165 | { 166 | CGSize expectedLabelSize = [self badgeExpectedSize]; 167 | 168 | CGFloat minHeight = expectedLabelSize.height; 169 | 170 | minHeight = (minHeight < self.badgeMinSize) ? self.badgeMinSize : expectedLabelSize.height; 171 | CGFloat minWidth = expectedLabelSize.width; 172 | CGFloat padding = self.badgePadding; 173 | 174 | minWidth = (minWidth < minHeight) ? minHeight : expectedLabelSize.width; 175 | self.badge.frame = CGRectMake(self.badgeOriginX, self.badgeOriginY, minWidth + padding, minHeight + padding); 176 | self.badge.layer.cornerRadius = (minHeight + padding) / 2; 177 | self.badge.layer.masksToBounds = YES; 178 | } 179 | 180 | - (void)updateBadgeValueAnimated:(BOOL)animated 181 | { 182 | if (animated && self.shouldAnimateBadge && ![self.badge.text isEqualToString:self.badgeValue]) { 183 | CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 184 | [animation setFromValue:[NSNumber numberWithFloat:1.5]]; 185 | [animation setToValue:[NSNumber numberWithFloat:1]]; 186 | [animation setDuration:0.2]; 187 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.4f :1.3f :1.f :1.f]]; 188 | [self.badge.layer addAnimation:animation forKey:@"bounceAnimation"]; 189 | } 190 | 191 | self.badge.text = self.badgeValue; 192 | 193 | NSTimeInterval duration = animated ? 0.2 : 0; 194 | [UIView animateWithDuration:duration animations:^{ 195 | [self updateBadgeFrame]; 196 | }]; 197 | } 198 | 199 | - (UILabel *)duplicateLabel:(UILabel *)labelToCopy 200 | { 201 | UILabel *duplicateLabel = [[UILabel alloc] initWithFrame:labelToCopy.frame]; 202 | duplicateLabel.text = labelToCopy.text; 203 | duplicateLabel.font = labelToCopy.font; 204 | 205 | return duplicateLabel; 206 | } 207 | 208 | - (void)removeBadge 209 | { 210 | 211 | [UIView animateWithDuration:0.2 animations:^{ 212 | self.badge.transform = CGAffineTransformMakeScale(0, 0); 213 | } completion:^(BOOL finished) { 214 | [self.badge removeFromSuperview]; 215 | self.badge = nil; 216 | }]; 217 | } 218 | 219 | #pragma mark - getters/setters 220 | -(UILabel*) badge { 221 | return objc_getAssociatedObject(self, &UIButton_badgeKey); 222 | } 223 | -(void)setBadge:(UILabel *)badgeLabel 224 | { 225 | objc_setAssociatedObject(self, &UIButton_badgeKey, badgeLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 226 | } 227 | 228 | 229 | -(NSString *)badgeValue { 230 | return objc_getAssociatedObject(self, &UIButton_badgeValueKey); 231 | } 232 | -(void) setBadgeValue:(NSString *)badgeValue 233 | { 234 | objc_setAssociatedObject(self, &UIButton_badgeValueKey, badgeValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 235 | 236 | 237 | if (!badgeValue || [badgeValue isEqualToString:@""] || ([badgeValue isEqualToString:@"0"] && self.shouldHideBadgeAtZero)) { 238 | [self removeBadge]; 239 | } else if (!self.badge) { 240 | // Create a new badge because not existing 241 | self.badge = [[UILabel alloc] initWithFrame:CGRectMake(self.badgeOriginX, self.badgeOriginY, 20, 20)]; 242 | self.badge.textColor = self.badgeTextColor; 243 | self.badge.backgroundColor = self.badgeBGColor; 244 | self.badge.font = self.badgeFont; 245 | self.badge.textAlignment = NSTextAlignmentCenter; 246 | [self badgeInit]; 247 | [self addSubview:self.badge]; 248 | [self updateBadgeValueAnimated:NO]; 249 | } else { 250 | [self updateBadgeValueAnimated:YES]; 251 | } 252 | } 253 | 254 | -(UIColor *)badgeBGColor { 255 | return objc_getAssociatedObject(self, &UIButton_badgeBGColorKey); 256 | } 257 | -(void)setBadgeBGColor:(UIColor *)badgeBGColor 258 | { 259 | objc_setAssociatedObject(self, &UIButton_badgeBGColorKey, badgeBGColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 260 | if (self.badge) { 261 | [self refreshBadge]; 262 | } 263 | } 264 | 265 | -(UIColor *)badgeTextColor { 266 | return objc_getAssociatedObject(self, &UIButton_badgeTextColorKey); 267 | } 268 | -(void)setBadgeTextColor:(UIColor *)badgeTextColor 269 | { 270 | objc_setAssociatedObject(self, &UIButton_badgeTextColorKey, badgeTextColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 271 | if (self.badge) { 272 | [self refreshBadge]; 273 | } 274 | } 275 | 276 | -(UIFont *)badgeFont { 277 | return objc_getAssociatedObject(self, &UIButton_badgeFontKey); 278 | } 279 | -(void)setBadgeFont:(UIFont *)badgeFont 280 | { 281 | objc_setAssociatedObject(self, &UIButton_badgeFontKey, badgeFont, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 282 | if (self.badge) { 283 | [self refreshBadge]; 284 | } 285 | } 286 | 287 | -(CGFloat) badgePadding { 288 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_badgePaddingKey); 289 | return number.floatValue; 290 | } 291 | -(void) setBadgePadding:(CGFloat)badgePadding 292 | { 293 | NSNumber *number = [NSNumber numberWithDouble:badgePadding]; 294 | objc_setAssociatedObject(self, &UIButton_badgePaddingKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 295 | if (self.badge) { 296 | [self updateBadgeFrame]; 297 | } 298 | } 299 | 300 | -(CGFloat) badgeMinSize { 301 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_badgeMinSizeKey); 302 | return number.floatValue; 303 | } 304 | -(void) setBadgeMinSize:(CGFloat)badgeMinSize 305 | { 306 | NSNumber *number = [NSNumber numberWithDouble:badgeMinSize]; 307 | objc_setAssociatedObject(self, &UIButton_badgeMinSizeKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 308 | if (self.badge) { 309 | [self updateBadgeFrame]; 310 | } 311 | } 312 | 313 | 314 | -(CGFloat) badgeOriginX { 315 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_badgeOriginXKey); 316 | return number.floatValue; 317 | } 318 | -(void) setBadgeOriginX:(CGFloat)badgeOriginX 319 | { 320 | NSNumber *number = [NSNumber numberWithDouble:badgeOriginX]; 321 | objc_setAssociatedObject(self, &UIButton_badgeOriginXKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 322 | if (self.badge) { 323 | [self updateBadgeFrame]; 324 | } 325 | } 326 | 327 | -(CGFloat) badgeOriginY { 328 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_badgeOriginYKey); 329 | return number.floatValue; 330 | } 331 | -(void) setBadgeOriginY:(CGFloat)badgeOriginY 332 | { 333 | NSNumber *number = [NSNumber numberWithDouble:badgeOriginY]; 334 | objc_setAssociatedObject(self, &UIButton_badgeOriginYKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 335 | if (self.badge) { 336 | [self updateBadgeFrame]; 337 | } 338 | } 339 | 340 | -(BOOL) shouldHideBadgeAtZero { 341 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_shouldHideBadgeAtZeroKey); 342 | return number.boolValue; 343 | } 344 | - (void)setShouldHideBadgeAtZero:(BOOL)shouldHideBadgeAtZero 345 | { 346 | NSNumber *number = [NSNumber numberWithBool:shouldHideBadgeAtZero]; 347 | objc_setAssociatedObject(self, &UIButton_shouldHideBadgeAtZeroKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 348 | } 349 | 350 | -(BOOL) shouldAnimateBadge { 351 | NSNumber *number = objc_getAssociatedObject(self, &UIButton_shouldAnimateBadgeKey); 352 | return number.boolValue; 353 | } 354 | - (void)setShouldAnimateBadge:(BOOL)shouldAnimateBadge 355 | { 356 | NSNumber *number = [NSNumber numberWithBool:shouldAnimateBadge]; 357 | objc_setAssociatedObject(self, &UIButton_shouldAnimateBadgeKey, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 358 | } 359 | 360 | 361 | 362 | - (UIEdgeInsets)clickEdgeInsets 363 | { 364 | return [objc_getAssociatedObject(self, @selector(clickEdgeInsets)) UIEdgeInsetsValue]; 365 | } 366 | 367 | - (void)setClickEdgeInsets:(UIEdgeInsets)clickEdgeInsets 368 | { 369 | objc_setAssociatedObject(self, @selector(clickEdgeInsets), [NSValue valueWithUIEdgeInsets:clickEdgeInsets], OBJC_ASSOCIATION_RETAIN_NONATOMIC); 370 | } 371 | 372 | - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 373 | { 374 | if (UIEdgeInsetsEqualToEdgeInsets(self.clickEdgeInsets, UIEdgeInsetsZero)) 375 | { 376 | return [super pointInside:point withEvent:event]; 377 | } 378 | else 379 | { 380 | CGRect large = UIEdgeInsetsInsetRect(self.bounds, self.clickEdgeInsets); 381 | return CGRectContainsPoint(large, point) ? YES : NO; 382 | } 383 | } 384 | 385 | @end 386 | -------------------------------------------------------------------------------- /WHKit/UIColor+WHColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WHColor.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (WHColor) 12 | 13 | /** 16进制数字创建颜色 */ 14 | + (instancetype)wh_colorWithHex:(uint32_t)hex; 15 | 16 | /** 随机色 */ 17 | + (instancetype)wh_randomColor; 18 | 19 | /** RGB颜色 */ 20 | + (instancetype)wh_colorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue; 21 | 22 | /** 23 | 十六进制字符串显示颜色 24 | 25 | @param color 十六进制字符串 26 | @param alpha 透明度 27 | @return 颜色 28 | */ 29 | + (UIColor *)wh_colorWithHexString:(NSString *)color alpha:(CGFloat)alpha; 30 | 31 | /** 32 | * @brief 渐变颜色 33 | * 34 | * @param fromColor 开始颜色 35 | * @param toColor 结束颜色 36 | * @param height 渐变高度 37 | * 38 | * @return 渐变颜色 39 | */ 40 | + (UIColor*)wh_gradientFromColor:(UIColor*)fromColor toColor:(UIColor*)toColor withHeight:(CGFloat)height; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /WHKit/UIColor+WHColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WHColor.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIColor+WHColor.h" 10 | 11 | @implementation UIColor (WHColor) 12 | 13 | + (instancetype)wh_colorWithHex:(uint32_t)hex { 14 | 15 | uint8_t r = (hex & 0xff0000) >> 16; 16 | uint8_t g = (hex & 0x00ff00) >> 8; 17 | uint8_t b = hex & 0x0000ff; 18 | 19 | return [self wh_colorWithRed:r green:g blue:b]; 20 | } 21 | 22 | + (instancetype)wh_randomColor { 23 | return [UIColor wh_colorWithRed:arc4random_uniform(256) green:arc4random_uniform(256) blue:arc4random_uniform(256)]; 24 | } 25 | 26 | + (instancetype)wh_colorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue { 27 | return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0]; 28 | } 29 | 30 | + (UIColor *)wh_colorWithHexString:(NSString *)color alpha:(CGFloat)alpha 31 | { 32 | NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; 33 | if ([cString length] < 6) 34 | { 35 | return [UIColor clearColor]; 36 | } 37 | 38 | if ([cString hasPrefix:@"0X"]) 39 | { 40 | cString = [cString substringFromIndex:2]; 41 | } 42 | if ([cString hasPrefix:@"#"]) 43 | { 44 | cString = [cString substringFromIndex:1]; 45 | } 46 | if ([cString length] != 6) 47 | { 48 | return [UIColor clearColor]; 49 | } 50 | 51 | NSRange range; 52 | range.location = 0; 53 | range.length = 2; 54 | //r 55 | NSString *rString = [cString substringWithRange:range]; 56 | //g 57 | range.location = 2; 58 | NSString *gString = [cString substringWithRange:range]; 59 | //b 60 | range.location = 4; 61 | NSString *bString = [cString substringWithRange:range]; 62 | 63 | unsigned int r, g, b; 64 | [[NSScanner scannerWithString:rString] scanHexInt:&r]; 65 | [[NSScanner scannerWithString:gString] scanHexInt:&g]; 66 | [[NSScanner scannerWithString:bString] scanHexInt:&b]; 67 | return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha]; 68 | } 69 | 70 | + (UIColor*)wh_gradientFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withHeight:(CGFloat)height 71 | { 72 | CGSize size = CGSizeMake(1, height); 73 | UIGraphicsBeginImageContextWithOptions(size, NO, 0); 74 | CGContextRef context = UIGraphicsGetCurrentContext(); 75 | CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); 76 | 77 | NSArray* colors = [NSArray arrayWithObjects:(id)c1.CGColor, (id)c2.CGColor, nil]; 78 | CGGradientRef gradient = CGGradientCreateWithColors(colorspace, (__bridge CFArrayRef)colors, NULL); 79 | CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0); 80 | 81 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 82 | 83 | CGGradientRelease(gradient); 84 | CGColorSpaceRelease(colorspace); 85 | UIGraphicsEndImageContext(); 86 | 87 | return [UIColor colorWithPatternImage:image]; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /WHKit/UIDevice+WHDevice.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+WHDevice.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIDevice (WHDevice) 12 | 13 | /** mac地址 */ 14 | + (NSString *)macAddress; 15 | 16 | /** ram的size */ 17 | + (NSUInteger)ramSize; 18 | 19 | /** cpu个数 */ 20 | + (NSUInteger)cpuNumber; 21 | 22 | /** 系统的版本号 */ 23 | + (NSString *)systemVersion; 24 | 25 | /** 是否有摄像头 */ 26 | + (BOOL)hasCamera; 27 | 28 | /** 获取手机内存总量, 返回的是字节数 */ 29 | + (NSUInteger)totalMemoryBytes; 30 | 31 | /** 获取手机可用内存, 返回的是字节数 */ 32 | + (NSUInteger)freeMemoryBytes; 33 | 34 | /** 获取手机硬盘总空间, 返回的是字节数 */ 35 | + (NSUInteger)totalDiskSpaceBytes; 36 | 37 | /** 获取手机硬盘空闲空间, 返回的是字节数 */ 38 | + (NSUInteger)freeDiskSpaceBytes; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /WHKit/UIDevice+WHDevice.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+WHDevice.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+WHDevice.h" 10 | #include 11 | #include 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | 23 | @implementation UIDevice (WHDevice) 24 | 25 | + (NSString *)macAddress { 26 | int mib[6]; 27 | size_t len; 28 | char *buf; 29 | unsigned char *ptr; 30 | struct if_msghdr *ifm; 31 | struct sockaddr_dl *sdl; 32 | 33 | mib[0] = CTL_NET; 34 | mib[1] = AF_ROUTE; 35 | mib[2] = 0; 36 | mib[3] = AF_LINK; 37 | mib[4] = NET_RT_IFLIST; 38 | 39 | if((mib[5] = if_nametoindex("en0")) == 0) { 40 | printf("Error: if_nametoindex error\n"); 41 | return NULL; 42 | } 43 | 44 | if(sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 45 | printf("Error: sysctl, take 1\n"); 46 | return NULL; 47 | } 48 | 49 | if((buf = malloc(len)) == NULL) { 50 | printf("Could not allocate memory. Rrror!\n"); 51 | return NULL; 52 | } 53 | 54 | if(sysctl(mib, 6, buf, &len, NULL, 0) < 0) { 55 | printf("Error: sysctl, take 2"); 56 | return NULL; 57 | } 58 | 59 | ifm = (struct if_msghdr *)buf; 60 | sdl = (struct sockaddr_dl *)(ifm + 1); 61 | ptr = (unsigned char *)LLADDR(sdl); 62 | NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 63 | *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; 64 | free(buf); 65 | 66 | return outstring; 67 | } 68 | 69 | + (NSString *)systemVersion 70 | { 71 | return [[UIDevice currentDevice] systemVersion]; 72 | } 73 | + (BOOL)hasCamera 74 | { 75 | return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; 76 | } 77 | 78 | + (NSUInteger)getSysInfo:(uint)typeSpecifier 79 | { 80 | size_t size = sizeof(int); 81 | int result; 82 | int mib[2] = {CTL_HW, typeSpecifier}; 83 | sysctl(mib, 2, &result, &size, NULL, 0); 84 | return (NSUInteger)result; 85 | } 86 | 87 | + (NSUInteger)ramSize { 88 | return [self getSysInfo:HW_MEMSIZE]; 89 | } 90 | 91 | + (NSUInteger)cpuNumber { 92 | return [self getSysInfo:HW_NCPU]; 93 | } 94 | 95 | 96 | + (NSUInteger)totalMemoryBytes 97 | { 98 | return [self getSysInfo:HW_PHYSMEM]; 99 | } 100 | 101 | + (NSUInteger)freeMemoryBytes 102 | { 103 | mach_port_t host_port = mach_host_self(); 104 | mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); 105 | vm_size_t pagesize; 106 | vm_statistics_data_t vm_stat; 107 | 108 | host_page_size(host_port, &pagesize); 109 | if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) { 110 | return 0; 111 | } 112 | unsigned long mem_free = vm_stat.free_count * pagesize; 113 | return mem_free; 114 | } 115 | 116 | + (NSUInteger)freeDiskSpaceBytes 117 | { 118 | NSFileManager *fileManager = [NSFileManager defaultManager]; 119 | NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 120 | NSNumber *number = attributes[NSFileSystemFreeSize]; 121 | return [number unsignedIntegerValue]; 122 | } 123 | 124 | + (NSUInteger)totalDiskSpaceBytes 125 | { 126 | NSFileManager *fileManager = [NSFileManager defaultManager]; 127 | NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 128 | NSNumber *number = attributes[NSFileSystemSize]; 129 | return [number unsignedIntegerValue]; 130 | } 131 | 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /WHKit/UIImage+WHImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WHImage.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^UIImageSizeRequestCompleted) (NSURL* imgURL, CGSize size); 12 | 13 | @interface UIImage (WHImage) 14 | 15 | /** 截屏 */ 16 | +(instancetype)wh_snapshotCurrentScreen; 17 | 18 | /** 图片模糊效果 */ 19 | - (UIImage *)blur; 20 | 21 | /** 圆角图片 */ 22 | - (UIImage *)imageWithCornerRadius:(CGFloat)radius; 23 | 24 | /** 圆角图片 */ 25 | - (UIImage*)wh_imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size; 26 | 27 | /** 圆形图片 */ 28 | + (UIImage *)wh_GetRoundImagewithImage:(UIImage *)image; 29 | 30 | /** 在图片上加居中的文字 */ 31 | - (UIImage *)wh_imageWithTitle:(NSString *)title fontSize:(CGFloat)fontSize titleColor:(UIColor *)titleColor; 32 | 33 | /** 34 | 取图片某一像素点的颜色 35 | 36 | @param point 图片上的某一点 37 | @return 图片上这一点的颜色 38 | */ 39 | - (UIColor *)wh_colorAtPixel:(CGPoint)point; 40 | 41 | /** 42 | 生成一个纯色的图片 43 | 44 | @param color 图片颜色 45 | @return 返回的纯色图片 46 | */ 47 | - (UIImage *)wh_imageWithColor:(UIColor *)color; 48 | 49 | /** 获得灰度图 */ 50 | - (UIImage *)wh_convertToGrayImage; 51 | 52 | /** 合并两个图片为一个图片 */ 53 | + (UIImage*)mergeImage:(UIImage*)firstImage withImage:(UIImage*)secondImage; 54 | 55 | /** 压缩图片 最大字节大小为maxLength */ 56 | - (NSData *)compressWithMaxLength:(NSInteger)maxLength; 57 | 58 | /** 纠正图片的方向 */ 59 | - (UIImage *)fixOrientation; 60 | 61 | /** 按给定的方向旋转图片 */ 62 | - (UIImage*)rotate:(UIImageOrientation)orient; 63 | 64 | /** 垂直翻转 */ 65 | - (UIImage *)flipVertical; 66 | 67 | /** 水平翻转 */ 68 | - (UIImage *)flipHorizontal; 69 | 70 | /** 将图片旋转degrees角度 */ 71 | - (UIImage *)imageRotatedByDegrees:(CGFloat)degrees; 72 | 73 | /** 将图片旋转radians弧度 */ 74 | - (UIImage *)imageRotatedByRadians:(CGFloat)radians; 75 | 76 | /** 截取当前image对象rect区域内的图像 */ 77 | - (UIImage *)subImageWithRect:(CGRect)rect; 78 | 79 | /** 压缩图片至指定尺寸 */ 80 | - (UIImage *)rescaleImageToSize:(CGSize)size; 81 | 82 | /** 压缩图片至指定像素 */ 83 | - (UIImage *)rescaleImageToPX:(CGFloat )toPX; 84 | 85 | /** 在指定的size里面生成一个平铺的图片 */ 86 | - (UIImage *)getTiledImageWithSize:(CGSize)size; 87 | 88 | /** UIView转化为UIImage */ 89 | + (UIImage *)imageFromView:(UIView *)view; 90 | 91 | /** 返回截取得到图片的某一块rect */ 92 | - (UIImage *)imageCroppedToRect:(CGRect)rect; 93 | 94 | /** 倒影 */ 95 | - (UIImage *)reflectedImageWithScale:(CGFloat)scale; 96 | 97 | /** 倒影 */ 98 | - (UIImage *)imageWithReflectionWithScale:(CGFloat)scale gap:(CGFloat)gap alpha:(CGFloat)alpha; 99 | 100 | /** 101 | 带有阴影的图片 102 | 103 | @param color 颜色 104 | @param offset offset 105 | @param blur 模糊度,可以先设置个20试试 106 | @return 带有阴影的图片 107 | */ 108 | - (UIImage *)imageWithShadowColor:(UIColor *)color offset:(CGSize)offset blur:(CGFloat)blur; 109 | 110 | /** 111 | 透明图片 112 | 113 | @param alpha 透明度 114 | @return 透明图片 115 | */ 116 | - (UIImage *)imageWithAlpha:(CGFloat)alpha; 117 | 118 | + (UIImage *)animatedImageWithAnimatedGIFData:(NSData *)theData; 119 | + (UIImage *)animatedImageWithAnimatedGIFURL:(NSURL *)theURL; 120 | - (UIImage *)imageScaledToSize:(CGSize)size; 121 | - (UIImage *)imageScaledToFitSize:(CGSize)size; 122 | - (UIImage *)imageScaledToFillSize:(CGSize)size; 123 | - (UIImage *)imageCroppedAndScaledToSize:(CGSize)size contentMode:(UIViewContentMode)contentMode padToFit:(BOOL)padToFit; 124 | - (UIImage *)imageWithMask:(UIImage *)maskImage; 125 | - (UIImage *)maskImageFromImageAlpha; 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /WHKit/UILabel+WHLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+WHLabel.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UILabel (WHLabel) 12 | 13 | /** 快速创建Label */ 14 | +(instancetype)wh_labelWithText:(NSString *)text textFont:(int)font textColor:(UIColor *)color frame:(CGRect)frame; 15 | 16 | /** 设置字间距 */ 17 | - (void)setColumnSpace:(CGFloat)columnSpace; 18 | 19 | /** 设置行距 */ 20 | - (void)setRowSpace:(CGFloat)rowSpace; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /WHKit/UILabel+WHLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+WHLabel.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UILabel+WHLabel.h" 10 | #import 11 | 12 | @implementation UILabel (WHLabel) 13 | 14 | +(instancetype)wh_labelWithText:(NSString *)text textFont:(int)font textColor:(UIColor *)color frame:(CGRect)frame{ 15 | UILabel *label = [UILabel new]; 16 | label.text = text; 17 | label.font = [UIFont systemFontOfSize:font]; 18 | label.textColor = color; 19 | label.textAlignment=YES; 20 | label.frame=frame; 21 | return label; 22 | } 23 | 24 | - (void)setColumnSpace:(CGFloat)columnSpace 25 | { 26 | NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; 27 | //调整间距 28 | [attributedString addAttribute:(__bridge NSString *)kCTKernAttributeName value:@(columnSpace) range:NSMakeRange(0, [attributedString length])]; 29 | self.attributedText = attributedString; 30 | } 31 | 32 | - (void)setRowSpace:(CGFloat)rowSpace 33 | { 34 | self.numberOfLines = 0; 35 | NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; 36 | //调整行距 37 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 38 | paragraphStyle.lineSpacing = rowSpace; 39 | paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight; 40 | paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail; 41 | [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.text length])]; 42 | self.attributedText = attributedString; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /WHKit/UINavigationController+WHNavigationController.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationController+WHNavigationController.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UINavigationController (WHNavigationController) 12 | 13 | /** 寻找Navigation中的某个viewcontroler */ 14 | - (id)findViewController:(Class)className; 15 | 16 | /** 判断是否只有一个RootViewController */ 17 | - (BOOL)isOnlyContainRootViewController; 18 | 19 | /** RootViewController */ 20 | - (UIViewController *)rootViewController; 21 | 22 | /** 返回指定的viewcontroler */ 23 | - (NSArray *)popToViewControllerWithClassName:(Class)className animated:(BOOL)animated; 24 | 25 | /** pop回第n层 */ 26 | - (NSArray *)popToViewControllerWithLevel:(NSInteger)level animated:(BOOL)animated; 27 | 28 | /** 以某种动画形式push */ 29 | - (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition; 30 | 31 | /** 以某种动画形式pop */ 32 | - (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /WHKit/UINavigationController+WHNavigationController.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationController+WHNavigationController.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UINavigationController+WHNavigationController.h" 10 | 11 | @implementation UINavigationController (WHNavigationController) 12 | 13 | - (id)findViewController:(Class)className; 14 | { 15 | for (UIViewController *viewController in self.viewControllers) 16 | { 17 | if ([viewController isKindOfClass:className]) 18 | { 19 | return viewController; 20 | } 21 | } 22 | 23 | return nil; 24 | } 25 | 26 | - (BOOL)isOnlyContainRootViewController 27 | { 28 | if (self.viewControllers && self.viewControllers.count == 1) 29 | { 30 | return YES; 31 | } 32 | return NO; 33 | } 34 | 35 | - (UIViewController *)rootViewController 36 | { 37 | if (self.viewControllers && [self.viewControllers count] >0) 38 | { 39 | return [self.viewControllers firstObject]; 40 | } 41 | return nil; 42 | } 43 | 44 | - (NSArray *)popToViewControllerWithClassName:(Class)className animated:(BOOL)animated; 45 | { 46 | return [self popToViewController:[self findViewController:className] animated:YES]; 47 | } 48 | 49 | - (NSArray *)popToViewControllerWithLevel:(NSInteger)level animated:(BOOL)animated 50 | { 51 | NSInteger viewControllersCount = self.viewControllers.count; 52 | if (viewControllersCount > level) { 53 | NSInteger idx = viewControllersCount - level - 1; 54 | UIViewController *viewController = self.viewControllers[idx]; 55 | return [self popToViewController:viewController animated:animated]; 56 | } else { 57 | return [self popToRootViewControllerAnimated:animated]; 58 | } 59 | } 60 | 61 | 62 | - (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition { 63 | [UIView beginAnimations:nil context:NULL]; 64 | [self pushViewController:controller animated:NO]; 65 | [UIView setAnimationDuration:0.5]; 66 | [UIView setAnimationBeginsFromCurrentState:YES]; 67 | [UIView setAnimationTransition:transition forView:self.view cache:YES]; 68 | [UIView commitAnimations]; 69 | } 70 | 71 | - (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition { 72 | [UIView beginAnimations:nil context:NULL]; 73 | UIViewController *controller = [self popViewControllerAnimated:NO]; 74 | [UIView setAnimationDuration:0.5]; 75 | [UIView setAnimationBeginsFromCurrentState:YES]; 76 | [UIView setAnimationTransition:transition forView:self.view cache:YES]; 77 | [UIView commitAnimations]; 78 | return controller; 79 | } 80 | 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /WHKit/UIScrollView+WHScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+WHScrollView.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIScrollView (WHScrollView) 12 | 13 | - (void)scrollToTop; 14 | 15 | - (void)scrollToBottom; 16 | 17 | - (void)scrollToLeft; 18 | 19 | - (void)scrollToRight; 20 | 21 | - (void)scrollToTopAnimated:(BOOL)animated; 22 | 23 | - (void)scrollToBottomAnimated:(BOOL)animated; 24 | 25 | - (void)scrollToLeftAnimated:(BOOL)animated; 26 | 27 | - (void)scrollToRightAnimated:(BOOL)animated; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /WHKit/UIScrollView+WHScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+WHScrollView.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIScrollView+WHScrollView.h" 10 | 11 | @implementation UIScrollView (WHScrollView) 12 | 13 | - (void)scrollToTop { 14 | [self scrollToTopAnimated:YES]; 15 | } 16 | 17 | - (void)scrollToBottom { 18 | [self scrollToBottomAnimated:YES]; 19 | } 20 | 21 | - (void)scrollToLeft { 22 | [self scrollToLeftAnimated:YES]; 23 | } 24 | 25 | - (void)scrollToRight { 26 | [self scrollToRightAnimated:YES]; 27 | } 28 | 29 | - (void)scrollToTopAnimated:(BOOL)animated { 30 | CGPoint off = self.contentOffset; 31 | off.y = 0 - self.contentInset.top; 32 | [self setContentOffset:off animated:animated]; 33 | } 34 | 35 | - (void)scrollToBottomAnimated:(BOOL)animated { 36 | CGPoint off = self.contentOffset; 37 | off.y = self.contentSize.height - self.bounds.size.height + self.contentInset.bottom; 38 | [self setContentOffset:off animated:animated]; 39 | } 40 | 41 | - (void)scrollToLeftAnimated:(BOOL)animated { 42 | CGPoint off = self.contentOffset; 43 | off.x = 0 - self.contentInset.left; 44 | [self setContentOffset:off animated:animated]; 45 | } 46 | 47 | - (void)scrollToRightAnimated:(BOOL)animated { 48 | CGPoint off = self.contentOffset; 49 | off.x = self.contentSize.width - self.bounds.size.width + self.contentInset.right; 50 | [self setContentOffset:off animated:animated]; 51 | } 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /WHKit/UITableView+WHTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+WHTableView.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (WHTableView) 12 | 13 | - (void)updateWithBlock:(void (^)(UITableView *tableView))block; 14 | 15 | - (void)scrollToRow:(NSUInteger)row inSection:(NSUInteger)section atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated; 16 | 17 | - (void)insertRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 18 | 19 | - (void)reloadRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 20 | 21 | - (void)deleteRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 22 | 23 | - (void)insertRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation; 24 | 25 | - (void)reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation; 26 | 27 | - (void)deleteRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation; 28 | 29 | - (void)insertSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 30 | 31 | - (void)deleteSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 32 | 33 | - (void)reloadSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation; 34 | 35 | - (void)clearSelectedRowsAnimated:(BOOL)animated; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /WHKit/UITableView+WHTableView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+WHTableView.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UITableView+WHTableView.h" 10 | 11 | @implementation UITableView (WHTableView) 12 | 13 | - (void)updateWithBlock:(void (^)(UITableView *tableView))block { 14 | [self beginUpdates]; 15 | block(self); 16 | [self endUpdates]; 17 | } 18 | 19 | - (void)scrollToRow:(NSUInteger)row inSection:(NSUInteger)section atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated { 20 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section]; 21 | [self scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated]; 22 | } 23 | 24 | - (void)insertRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation { 25 | [self insertRowsAtIndexPaths:@[indexPath] withRowAnimation:animation]; 26 | } 27 | 28 | - (void)insertRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 29 | NSIndexPath *toInsert = [NSIndexPath indexPathForRow:row inSection:section]; 30 | [self insertRowAtIndexPath:toInsert withRowAnimation:animation]; 31 | } 32 | 33 | - (void)reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation { 34 | [self reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:animation]; 35 | } 36 | 37 | - (void)reloadRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 38 | NSIndexPath *toReload = [NSIndexPath indexPathForRow:row inSection:section]; 39 | [self reloadRowAtIndexPath:toReload withRowAnimation:animation]; 40 | } 41 | 42 | - (void)deleteRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation { 43 | [self deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:animation]; 44 | } 45 | 46 | - (void)deleteRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 47 | NSIndexPath *toDelete = [NSIndexPath indexPathForRow:row inSection:section]; 48 | [self deleteRowAtIndexPath:toDelete withRowAnimation:animation]; 49 | } 50 | 51 | - (void)insertSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 52 | NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section]; 53 | [self insertSections:sections withRowAnimation:animation]; 54 | } 55 | 56 | - (void)deleteSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 57 | NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section]; 58 | [self deleteSections:sections withRowAnimation:animation]; 59 | } 60 | 61 | - (void)reloadSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation { 62 | NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section]; 63 | [self reloadSections:indexSet withRowAnimation:animation]; 64 | } 65 | 66 | - (void)clearSelectedRowsAnimated:(BOOL)animated { 67 | NSArray *indexs = [self indexPathsForSelectedRows]; 68 | [indexs enumerateObjectsUsingBlock:^(NSIndexPath* path, NSUInteger idx, BOOL *stop) { 69 | [self deselectRowAtIndexPath:path animated:animated]; 70 | }]; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /WHKit/UIView+WHView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WHView.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^TapActionBlock)(UITapGestureRecognizer *gestureRecoginzer); 12 | typedef void (^LongPressActionBlock)(UILongPressGestureRecognizer *gestureRecoginzer); 13 | 14 | @interface UIView (WHView) 15 | 16 | @property (nonatomic, assign) CGFloat x; 17 | @property (nonatomic, assign) CGFloat y; 18 | @property (nonatomic, assign) CGFloat width; 19 | @property (nonatomic, assign) CGFloat height; 20 | @property (nonatomic, assign) CGSize size; 21 | @property (nonatomic, assign) CGFloat centerX; 22 | @property (nonatomic, assign) CGFloat centerY; 23 | 24 | /** 截取成图片 */ 25 | - (UIImage *)wh_snapshotImage; 26 | 27 | /** 触发点击事件 */ 28 | - (void)wh_addTapActionWithBlock:(TapActionBlock)block; 29 | 30 | /** 触发长按事件 */ 31 | - (void)wh_addLongPressActionWithBlock:(LongPressActionBlock)block; 32 | 33 | /** 找到指定类名的subView */ 34 | - (UIView *)wh_findSubViewWithClass:(Class)clazz; 35 | 36 | /** 找到指定类名的所有subView */ 37 | - (NSArray *)wh_findAllSubViewsWithClass:(Class)clazz; 38 | 39 | /** 找到指定类名的superView对象 */ 40 | - (UIView *)wh_findSuperViewWithClass:(Class)clazz; 41 | 42 | /** 找到view上的第一响应者 */ 43 | - (UIView *)wh_findFirstResponder; 44 | 45 | /** 找到当前view所在的viewcontroler */ 46 | - (UIViewController *)wh_findViewController; 47 | 48 | /** 所有子View */ 49 | - (NSArray *)wh_allSubviews; 50 | 51 | /** 移除所有子视图 */ 52 | - (void)wh_removeAllSubviews; 53 | 54 | @property (assign,nonatomic) IBInspectable NSInteger cornerRadius; 55 | @property (assign,nonatomic) IBInspectable BOOL masksToBounds; 56 | @property (assign,nonatomic) IBInspectable NSInteger borderWidth; 57 | @property (strong,nonatomic) IBInspectable NSString *borderHexRgb; 58 | @property (strong,nonatomic) IBInspectable UIColor *borderColor; 59 | 60 | + (instancetype)wh_loadViewFromNib; 61 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName; 62 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner; 63 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /WHKit/UIView+WHView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WHView.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIView+WHView.h" 10 | #import 11 | 12 | static char kActionHandlerTapBlockKey; 13 | static char kActionHandlerTapGestureKey; 14 | static char kActionHandlerLongPressBlockKey; 15 | static char kActionHandlerLongPressGestureKey; 16 | 17 | @implementation UIView (WHView) 18 | 19 | - (void)setX:(CGFloat)x{ 20 | CGRect frame = self.frame; 21 | frame.origin.x = x; 22 | self.frame = frame; 23 | } 24 | 25 | - (CGFloat)x{ 26 | return self.frame.origin.x; 27 | } 28 | 29 | - (void)setY:(CGFloat)y{ 30 | CGRect frame = self.frame; 31 | frame.origin.y = y; 32 | self.frame = frame; 33 | } 34 | 35 | - (CGFloat)y{ 36 | return self.frame.origin.y; 37 | } 38 | 39 | 40 | - (void)setWidth:(CGFloat)width{ 41 | CGRect frame = self.frame; 42 | frame.size.width = width; 43 | self.frame = frame; 44 | } 45 | 46 | - (CGFloat)width{ 47 | return self.frame.size.width; 48 | } 49 | 50 | - (void)setHeight:(CGFloat)height{ 51 | CGRect frame = self.frame; 52 | frame.size.height = height; 53 | self.frame = frame; 54 | } 55 | 56 | - (CGFloat)height{ 57 | return self.frame.size.height; 58 | } 59 | 60 | 61 | - (void)setCenterX:(CGFloat)centerX{ 62 | CGPoint point = self.center; 63 | point.x = centerX; 64 | self.center = point; 65 | } 66 | 67 | - (CGFloat)centerX{ 68 | return self.center.x; 69 | } 70 | 71 | - (void)setCenterY:(CGFloat)centerY{ 72 | CGPoint point = self.center; 73 | point.y = centerY; 74 | self.center = point; 75 | } 76 | 77 | - (CGFloat)centerY{ 78 | return self.center.y; 79 | } 80 | 81 | - (void)setSize:(CGSize)size{ 82 | CGRect frame = self.frame; 83 | frame.size = size; 84 | self.frame = frame; 85 | } 86 | 87 | 88 | - (CGSize)size{ 89 | return self.frame.size; 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 97 | - (void)wh_addTapActionWithBlock:(TapActionBlock)block 98 | { 99 | UITapGestureRecognizer *gesture = objc_getAssociatedObject(self, &kActionHandlerTapGestureKey); 100 | if (!gesture) 101 | { 102 | gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleActionForTapGesture:)]; 103 | [self addGestureRecognizer:gesture]; 104 | objc_setAssociatedObject(self, &kActionHandlerTapGestureKey, gesture, OBJC_ASSOCIATION_RETAIN); 105 | } 106 | objc_setAssociatedObject(self, &kActionHandlerTapBlockKey, block, OBJC_ASSOCIATION_COPY); 107 | } 108 | 109 | - (void)handleActionForTapGesture:(UITapGestureRecognizer *)gesture 110 | { 111 | if (gesture.state == UIGestureRecognizerStateRecognized) 112 | { 113 | TapActionBlock block = objc_getAssociatedObject(self, &kActionHandlerTapBlockKey); 114 | if (block) 115 | { 116 | block(gesture); 117 | } 118 | } 119 | } 120 | 121 | - (void)wh_addLongPressActionWithBlock:(LongPressActionBlock)block 122 | { 123 | UILongPressGestureRecognizer *gesture = objc_getAssociatedObject(self, &kActionHandlerLongPressGestureKey); 124 | if (!gesture) 125 | { 126 | gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleActionForLongPressGesture:)]; 127 | [self addGestureRecognizer:gesture]; 128 | objc_setAssociatedObject(self, &kActionHandlerLongPressGestureKey, gesture, OBJC_ASSOCIATION_RETAIN); 129 | } 130 | objc_setAssociatedObject(self, &kActionHandlerLongPressBlockKey, block, OBJC_ASSOCIATION_COPY); 131 | } 132 | 133 | - (void)handleActionForLongPressGesture:(UILongPressGestureRecognizer *)gesture 134 | { 135 | if (gesture.state == UIGestureRecognizerStateRecognized) 136 | { 137 | LongPressActionBlock block = objc_getAssociatedObject(self, &kActionHandlerLongPressBlockKey); 138 | if (block) 139 | { 140 | block(gesture); 141 | } 142 | } 143 | } 144 | 145 | 146 | 147 | 148 | - (UIView *)wh_findSubViewWithClass:(Class)clazz; 149 | { 150 | for (UIView * subView in self.subviews) 151 | { 152 | if ([subView isKindOfClass:clazz]) 153 | { 154 | return subView; 155 | } 156 | } 157 | 158 | return nil; 159 | } 160 | 161 | - (NSArray *)wh_findAllSubViewsWithClass:(Class)clazz 162 | { 163 | NSMutableArray *array = [NSMutableArray array]; 164 | 165 | for (UIView * subView in self.subviews) 166 | { 167 | if ([subView isKindOfClass:clazz]) 168 | { 169 | [array addObject:subView]; 170 | } 171 | } 172 | 173 | return array; 174 | } 175 | 176 | - (UIView *)wh_findSuperViewWithClass:(Class)clazz; 177 | { 178 | if (self == nil) 179 | { 180 | return nil; 181 | } 182 | else if (self.superview == nil) 183 | { 184 | return nil; 185 | } 186 | else if ([self.superview isKindOfClass:clazz]) 187 | { 188 | return self.superview; 189 | } 190 | else 191 | { 192 | return [self.superview wh_findSuperViewWithClass:clazz]; 193 | } 194 | } 195 | 196 | - (UIView *)wh_findFirstResponder 197 | { 198 | if (([self isKindOfClass:[UITextField class]] || [self isKindOfClass:[UITextView class]]) 199 | && (self.isFirstResponder)) 200 | { 201 | return self; 202 | } 203 | 204 | for (UIView *v in self.subviews) 205 | { 206 | UIView *fv = [v wh_findFirstResponder]; 207 | if (fv) 208 | { 209 | return fv; 210 | } 211 | } 212 | 213 | return nil; 214 | } 215 | 216 | - (UIViewController *)wh_findViewController; 217 | { 218 | UIResponder *responder = self.nextResponder; 219 | do 220 | { 221 | if ([responder isKindOfClass:[UIViewController class]]) 222 | { 223 | return (UIViewController *)responder; 224 | } 225 | responder = responder.nextResponder; 226 | } 227 | while (responder); 228 | 229 | return nil; 230 | } 231 | 232 | - (void)wh_removeAllSubviews 233 | { 234 | [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 235 | } 236 | 237 | - (NSArray *)wh_allSubviews 238 | { 239 | NSMutableArray *array = [NSMutableArray arrayWithCapacity:0]; 240 | 241 | [array addObjectsFromArray:self.subviews]; 242 | 243 | for (UIView *view in self.subviews) 244 | { 245 | [array addObjectsFromArray:[view wh_allSubviews]]; 246 | } 247 | 248 | return array; 249 | } 250 | 251 | 252 | 253 | + (instancetype)wh_loadViewFromNib 254 | { 255 | return [self wh_loadViewFromNibWithName:NSStringFromClass([self class])]; 256 | } 257 | 258 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName 259 | { 260 | return [self wh_loadViewFromNibWithName:nibName owner:nil]; 261 | } 262 | 263 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner 264 | { 265 | return [self wh_loadViewFromNibWithName:nibName owner:owner bundle:[NSBundle mainBundle]]; 266 | } 267 | 268 | + (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle 269 | { 270 | UIView *result = nil; 271 | NSArray* elements = [bundle loadNibNamed:nibName owner:owner options:nil]; 272 | for (id object in elements) 273 | { 274 | if ([object isKindOfClass:[self class]]) 275 | { 276 | result = object; 277 | break; 278 | } 279 | } 280 | return result; 281 | } 282 | 283 | 284 | 285 | 286 | - (void)setCornerRadius:(NSInteger)cornerRadius 287 | { 288 | self.layer.cornerRadius = cornerRadius; 289 | self.layer.masksToBounds = cornerRadius > 0; 290 | } 291 | 292 | - (NSInteger)cornerRadius 293 | { 294 | return self.layer.cornerRadius; 295 | } 296 | 297 | - (void)setBorderWidth:(NSInteger)borderWidth 298 | { 299 | self.layer.borderWidth = borderWidth; 300 | } 301 | 302 | - (NSInteger)borderWidth 303 | { 304 | return self.layer.borderWidth; 305 | } 306 | 307 | - (void)setBorderColor:(UIColor *)borderColor 308 | { 309 | self.layer.borderColor = borderColor.CGColor; 310 | } 311 | 312 | - (UIColor *)borderColor 313 | { 314 | return [UIColor colorWithCGColor:self.layer.borderColor]; 315 | } 316 | 317 | - (void)setBorderHexRgb:(NSString *)borderHexRgb 318 | { 319 | NSScanner *scanner = [NSScanner scannerWithString:borderHexRgb]; 320 | unsigned hexNum; 321 | //这里是将16进制转化为10进制 322 | if (![scanner scanHexInt:&hexNum]) 323 | return; 324 | self.layer.borderColor = [self colorWithRGBHex:hexNum].CGColor; 325 | } 326 | 327 | -(NSString *)borderHexRgb 328 | { 329 | return @"0xffffff"; 330 | } 331 | 332 | - (void)setMasksToBounds:(BOOL)bounds 333 | { 334 | self.layer.masksToBounds = bounds; 335 | } 336 | 337 | - (BOOL)masksToBounds 338 | { 339 | return self.layer.masksToBounds; 340 | } 341 | 342 | - (UIColor *)colorWithRGBHex:(UInt32)hex 343 | { 344 | int r = (hex >> 16) & 0xFF; 345 | int g = (hex >> 8) & 0xFF; 346 | int b = (hex) & 0xFF; 347 | 348 | return [UIColor colorWithRed:r / 255.0f 349 | green:g / 255.0f 350 | blue:b / 255.0f 351 | alpha:1.0f]; 352 | } 353 | 354 | 355 | - (UIImage *)wh_snapshotImage { 356 | 357 | UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); 358 | 359 | [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; 360 | 361 | UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 362 | 363 | UIGraphicsEndImageContext(); 364 | 365 | return result; 366 | } 367 | 368 | @end 369 | -------------------------------------------------------------------------------- /WHKit/UIViewController+WHVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+WHVC.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIViewController (WHVC) 12 | 13 | /** 找到当前视图控制器 */ 14 | + (UIViewController *)wh_currentViewController; 15 | 16 | /** 找到当前导航控制器 */ 17 | + (UINavigationController *)wh_currentNavigatonController; 18 | 19 | /** 在当前视图控制器中添加子控制器,将子控制器的视图添加到view中 */ 20 | - (void)wh_addChildController:(UIViewController *)childController intoView:(UIView *)view; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /WHKit/UIViewController+WHVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+WHVC.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "UIViewController+WHVC.h" 10 | #import "WHMacro.h" 11 | 12 | @implementation UIViewController (WHVC) 13 | 14 | + (UIViewController *)findBestViewController:(UIViewController *)vc 15 | { 16 | if (vc.presentedViewController) 17 | { 18 | return [self findBestViewController:vc.presentedViewController]; 19 | } 20 | else if ([vc isKindOfClass:[UISplitViewController class]]) 21 | { 22 | UISplitViewController* svc = (UISplitViewController*) vc; 23 | if (svc.viewControllers.count > 0) 24 | { 25 | return [self findBestViewController:svc.viewControllers.lastObject]; 26 | } 27 | else 28 | { 29 | return vc; 30 | } 31 | 32 | } 33 | else if ([vc isKindOfClass:[UINavigationController class]]) 34 | { 35 | UINavigationController* svc = (UINavigationController*) vc; 36 | if (svc.viewControllers.count > 0) 37 | { 38 | return [self findBestViewController:svc.topViewController]; 39 | } 40 | else 41 | { 42 | return vc; 43 | } 44 | 45 | } 46 | else if ([vc isKindOfClass:[UITabBarController class]]) 47 | { 48 | UITabBarController* svc = (UITabBarController *)vc; 49 | if (svc.viewControllers.count > 0) 50 | { 51 | return [self findBestViewController:svc.selectedViewController]; 52 | } 53 | else 54 | { 55 | return vc; 56 | } 57 | 58 | } 59 | else 60 | { 61 | return vc; 62 | } 63 | } 64 | 65 | + (UIViewController *)wh_currentViewController { 66 | UIViewController *viewController = KCurrentWindow.rootViewController; 67 | return [UIViewController findBestViewController:viewController]; 68 | } 69 | 70 | + (UINavigationController *)wh_currentNavigatonController { 71 | 72 | UIViewController * currentViewController = [UIViewController wh_currentViewController]; 73 | 74 | return currentViewController.navigationController; 75 | } 76 | 77 | - (void)wh_addChildController:(UIViewController *)childController intoView:(UIView *)view { 78 | 79 | [self addChildViewController:childController]; 80 | 81 | [view addSubview:childController.view]; 82 | 83 | [childController didMoveToParentViewController:self]; 84 | } 85 | 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /WHKit/WHKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // WHKit.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/15. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | #import 23 | #import 24 | #import 25 | #import 26 | #import 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | 33 | #import 34 | 35 | #import 36 | #import 37 | #import 38 | -------------------------------------------------------------------------------- /WHKit/WHMacro.h: -------------------------------------------------------------------------------- 1 | // 2 | // WHMacro.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | static inline UIWindow* wh_currentWindow() { 10 | UIWindow* window = nil; 11 | if (@available(iOS 13.0, *)) { 12 | for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes) { 13 | if (windowScene.activationState == UISceneActivationStateForegroundActive) { 14 | window = windowScene.windows.firstObject; 15 | break; 16 | } 17 | } 18 | } else { 19 | #pragma clang diagnostic push 20 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 21 | window = [UIApplication sharedApplication].keyWindow; 22 | #pragma clang diagnostic pop 23 | } 24 | return window; 25 | } 26 | 27 | static inline BOOL isIphoneX() { 28 | BOOL result = NO; 29 | if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) { 30 | return result; 31 | } 32 | if (@available(iOS 11.0, *)) { 33 | if (wh_currentWindow().safeAreaInsets.bottom > 0.0) { 34 | result = YES; 35 | } 36 | } 37 | return result; 38 | } 39 | 40 | //NSLog 41 | #ifdef DEBUG 42 | #define NSLog(...) NSLog(@"%s 第%d行: %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__]) 43 | #else 44 | #define NSLog(...) 45 | #endif 46 | 47 | //APP版本号 48 | #define KAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] 49 | //系统版本号 50 | #define kSystemVersion [[UIDevice currentDevice] systemVersion] 51 | 52 | //黑色和白色 53 | #define kWhiteColor [UIColor whiteColor] 54 | #define kBlackColor [UIColor blackColor] 55 | 56 | // View 圆角和加边框 57 | #define kViewBorderRadius(View, Radius, Width, Color)\ 58 | \ 59 | [View.layer setCornerRadius:(Radius)];\ 60 | [View.layer setMasksToBounds:YES];\ 61 | [View.layer setBorderWidth:(Width)];\ 62 | [View.layer setBorderColor:[Color CGColor]] 63 | 64 | // View 圆角 65 | #define kViewRadius(View, Radius)\ 66 | \ 67 | [View.layer setCornerRadius:(Radius)];\ 68 | [View.layer setMasksToBounds:YES] 69 | 70 | //字符串是否为空 71 | #define kIsStringEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO ) 72 | //数组是否为空 73 | #define kIsArrayEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0) 74 | //字典是否为空 75 | #define kIsDictEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0) 76 | //是否是空对象 77 | #define kIsObjectEmpty(_object) (_object == nil \ 78 | || [_object isKindOfClass:[NSNull class]] \ 79 | || ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \ 80 | || ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0)) 81 | 82 | //屏幕宽度 83 | #define kScreenWidth \ 84 | ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width) 85 | //屏幕高度 86 | #define kScreenHeight \ 87 | ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height) 88 | //屏幕Size 89 | #define kScreenSize \ 90 | ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size) 91 | //状态栏加导航栏高度 92 | #define kTopHeight (kIs_iPhoneX ? 88 : 64) 93 | //TabBar高度 94 | #define kTabBarHeight (kIs_iPhoneX ? 83 : 49) 95 | 96 | //Aplication 97 | #define kApplication [UIApplication sharedApplication] 98 | //currentWindow 99 | #define kKeyWindow (wh_currentWindow()) 100 | //currentWindow 101 | #define KCurrentWindow (wh_currentWindow()) 102 | //AppDelegate 103 | #define kAppdelegate [UIApplication sharedApplication].delegate 104 | //UserDefaults 105 | #define kUserDefault [NSUserDefaults standardUserDefaults] 106 | //NSNotificationCenter 107 | #define kNotificationCenter [NSNotificationCenter defaultCenter] 108 | 109 | //获取当前语言 110 | #define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) 111 | //判断是否为iPhone 112 | #define kIs_iPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 113 | //判断是否为iPad 114 | #define kIs_iPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 115 | 116 | //获取沙盒Document路径 117 | #define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] 118 | //获取沙盒temp路径 119 | #define kTempPath NSTemporaryDirectory() 120 | //获取沙盒Cache路径 121 | #define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] 122 | 123 | //判断是真机还是模拟器 124 | #if TARGET_OS_IPHONE 125 | //真机 126 | #endif 127 | 128 | #if TARGET_IPHONE_SIMULATOR 129 | //模拟器 130 | #endif 131 | 132 | //颜色 133 | #define kRGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] 134 | #define kRGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a] 135 | #define kRandomColor KRGB_COLOR(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256)) 136 | 137 | 138 | /** 139 | 十六进制表示颜色 140 | 141 | @param hexValue 十六进制值,不是字符串 142 | @param alphaValue 透明度 143 | @return 颜色 144 | */ 145 | #define kHexColor(hexValue, alphaValue) \ 146 | [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 \ 147 | green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 \ 148 | blue:((float)(hexValue & 0xFF)) / 255.0 alpha:alphaValue] 149 | 150 | //弱引用/强引用 151 | #define kWeakSelf(type) __weak typeof(type) weak##type = type; 152 | #define kStrongSelf(type) __strong typeof(type) type = weak##type; 153 | 154 | // 必须成对使用,使用该宏前必须加@,如@weakify(self); @strongify(self); 155 | #define weakify( x ) autoreleasepool{} __weak typeof(x) weak##x = x 156 | #define strongify( x ) autoreleasepool{} __strong typeof(weak##x) x = weak##x 157 | #define onExit(deferBlock) \ 158 | autoreleasepool{} __strong nob_defer_block_t nob_macro_concat(__nob_stack_defer_block_, __LINE__) __attribute__((cleanup(nob_deferFunc), unused)) = deferBlock 159 | 160 | //由角度转换弧度 161 | #define kDegreesToRadian(x) (M_PI * (x) / 180.0) 162 | //由弧度转换角度 163 | #define kRadianToDegrees(radian) (radian * 180.0) / (M_PI) 164 | 165 | //获取一段时间间隔 166 | #define kStart CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); 167 | #define KEnd NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start) 168 | 169 | // 图片 170 | #define kImageOfFile(NAME,EXT) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]] 171 | #define kImageNamed(NAME) [UIImage imageNamed:NAME] 172 | 173 | // 多行文本获取高度 174 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0 175 | #define kMultiLineTextSize(text, font, maxSize) [text length] > 0 ? [text \ 176 | boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \ 177 | attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero; 178 | #else 179 | #define kMultiLineTextSize(text, font, maxSize) [text length] > 0 ? [text \ 180 | sizeWithFont:font constrainedToSize:maxSize] : CGSizeZero; 181 | #endif 182 | 183 | // 字体大小(常规/粗体) 184 | #define kBoldFont(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE] 185 | #define kSystemFont(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE] 186 | #define kFont(NAME,FONTSIZE) [UIFont fontWithName:(NAME) size:(FONTSIZE)] 187 | 188 | // 是否为iPhone X 189 | #define kIs_iPhoneX (isIphoneX()) 190 | -------------------------------------------------------------------------------- /WHKit/WHMethods.h: -------------------------------------------------------------------------------- 1 | // 2 | // WHMethods.h 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WHMethods : UIViewController 12 | 13 | /** 为控制器添加背景图片 */ 14 | + (void)wh_addBackgroundImageWithImageName:(NSString *)imageName forViewController:(UIViewController *)viewController; 15 | 16 | /** 获取数组中的最大值 */ 17 | + (CGFloat) wh_maxNumberFromArray:(NSArray *)array; 18 | 19 | /** 获取数组中的最小值 */ 20 | + (CGFloat) wh_minNumberFromArray:(NSArray *)array; 21 | 22 | /** 获取数组的和 */ 23 | + (CGFloat) wh_sumNumberFromArray:(NSArray *)array; 24 | 25 | /** 获取数组平均值 */ 26 | + (CGFloat) wh_averageNumberFromArray:(NSArray *)array; 27 | 28 | /** 可用硬件容量 */ 29 | + (CGFloat) wh_usableHardDriveCapacity; 30 | 31 | /** 硬件总容量 */ 32 | + (CGFloat) wh_allHardDriveCapacity; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /WHKit/WHMethods.m: -------------------------------------------------------------------------------- 1 | // 2 | // WHMethods.m 3 | // WHKit 4 | // https://github.com/remember17/WHKit 5 | // Created by 吴浩 on 2017/6/7. 6 | // Copyright © 2017年 remember17. All rights reserved. 7 | // 8 | 9 | #import "WHMethods.h" 10 | 11 | @interface WHMethods () 12 | 13 | @end 14 | 15 | @implementation WHMethods 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | } 20 | 21 | +(void)wh_addBackgroundImageWithImageName:(NSString *)imageName forViewController:(UIViewController *)viewController { 22 | //给控制器添加背景图片 23 | UIImage *oldImage = [UIImage imageNamed:imageName]; 24 | UIGraphicsBeginImageContextWithOptions(viewController.view.frame.size, NO, 0.0); 25 | [oldImage drawInRect:viewController.view.bounds]; 26 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 27 | UIGraphicsEndImageContext(); 28 | viewController.view.backgroundColor = [UIColor colorWithPatternImage:newImage]; 29 | } 30 | 31 | 32 | + (CGFloat) wh_maxNumberFromArray:(NSArray *)array { 33 | CGFloat max = 0; 34 | max =[[array valueForKeyPath:@"@max.floatValue"] floatValue]; 35 | return max; 36 | } 37 | 38 | + (CGFloat) wh_minNumberFromArray:(NSArray *)array{ 39 | CGFloat min = 0; 40 | min =[[array valueForKeyPath:@"@min.floatValue"] floatValue]; 41 | return min; 42 | } 43 | 44 | + (CGFloat) wh_sumNumberFromArray:(NSArray *)array{ 45 | CGFloat sum = 0; 46 | sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue]; 47 | return sum; 48 | } 49 | 50 | + (CGFloat) wh_averageNumberFromArray:(NSArray *)array{ 51 | CGFloat avg = 0; 52 | avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue]; 53 | return avg; 54 | } 55 | 56 | 57 | + (CGFloat) wh_usableHardDriveCapacity { 58 | CGFloat usable = 0; 59 | NSFileManager *fileManager = [NSFileManager defaultManager]; 60 | NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 61 | usable = [attributes[NSFileSystemFreeSize] doubleValue] / powf(1024, 3); 62 | NSLog(@"可用%.2fG",[attributes[NSFileSystemFreeSize] doubleValue] / powf(1024, 3)); 63 | return usable; 64 | } 65 | 66 | 67 | + (CGFloat) wh_allHardDriveCapacity { 68 | CGFloat all = 0; 69 | NSFileManager *fileManager = [NSFileManager defaultManager]; 70 | NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 71 | all = [attributes[NSFileSystemSize] doubleValue] / (powf(1024, 3)); 72 | NSLog(@"容量%.2fG",[attributes[NSFileSystemSize] doubleValue] / (powf(1024, 3))); 73 | return all; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /WHKit/WHSingleton.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // WHSingleton.h 4 | // WHKit 5 | // https://github.com/remember17/WHKit 6 | // Created by 吴浩 on 2017/7/21. 7 | // Copyright © 2017年 remember17. All rights reserved. 8 | // 9 | 10 | #define WHSingletonH(ClassName) +(instancetype) share##ClassName; 11 | 12 | #define WHSingletonM(ClassName) static id _instance;\ 13 | \ 14 | +(instancetype)allocWithZone:(struct _NSZone *)zone\ 15 | {\ 16 | static dispatch_once_t onceToken;\ 17 | dispatch_once(&onceToken, ^{\ 18 | _instance = [super allocWithZone:zone];\ 19 | });\ 20 | \ 21 | return _instance;\ 22 | }\ 23 | \ 24 | \ 25 | +(instancetype)share##ClassName\ 26 | {\ 27 | static dispatch_once_t onceToken;\ 28 | dispatch_once(&onceToken, ^{\ 29 | _instance = [[self alloc] init];\ 30 | });\ 31 | \ 32 | return _instance;\ 33 | }\ 34 | \ 35 | \ 36 | -(id)copyWithZone:(NSZone *)zone\ 37 | {\ 38 | return _instance;\ 39 | }\ 40 | \ 41 | \ 42 | - (id)mutableCopyWithZone:(nullable NSZone *)zone\ 43 | {\ 44 | return _instance;\ 45 | } 46 | -------------------------------------------------------------------------------- /WHKitDemo/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | target 'WHKitDemo' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for WHKitDemo 9 | pod 'WHKit', :path => '../' 10 | end 11 | -------------------------------------------------------------------------------- /WHKitDemo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - WHKit (1.8.0) 3 | 4 | DEPENDENCIES: 5 | - WHKit (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | WHKit: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | WHKit: e7fd9bcc45f185d207c649801c1ea9d18ba31327 13 | 14 | PODFILE CHECKSUM: 4c052a1f8899b9918dcaf408a2fd93efb61ef168 15 | 16 | COCOAPODS: 1.10.1 17 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Local Podspecs/WHKit.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WHKit", 3 | "version": "1.8.0", 4 | "summary": "Make development easier.", 5 | "homepage": "https://github.com/remember17/WHKit", 6 | "license": "MIT", 7 | "authors": { 8 | "wuhao": "503007958@qq.com" 9 | }, 10 | "platforms": { 11 | "ios": "11.0" 12 | }, 13 | "source": { 14 | "git": "https://github.com/remember17/WHKit.git", 15 | "tag": "1.8.0" 16 | }, 17 | "source_files": [ 18 | "WHKit", 19 | "WHKit/*.{h,m}" 20 | ], 21 | "frameworks": "UIKit", 22 | "requires_arc": true 23 | } 24 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - WHKit (1.8.0) 3 | 4 | DEPENDENCIES: 5 | - WHKit (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | WHKit: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | WHKit: e7fd9bcc45f185d207c649801c1ea9d18ba31327 13 | 14 | PODFILE CHECKSUM: 4c052a1f8899b9918dcaf408a2fd93efb61ef168 15 | 16 | COCOAPODS: 1.10.1 17 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## WHKit 5 | 6 | MIT License 7 | 8 | Copyright (c) 2017 wuhao 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | Generated by CocoaPods - https://cocoapods.org 29 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | MIT License 18 | 19 | Copyright (c) 2017 wuhao 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to deal 23 | in the Software without restriction, including without limitation the rights 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 25 | copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 | SOFTWARE. 38 | 39 | License 40 | MIT 41 | Title 42 | WHKit 43 | Type 44 | PSGroupSpecifier 45 | 46 | 47 | FooterText 48 | Generated by CocoaPods - https://cocoapods.org 49 | Title 50 | 51 | Type 52 | PSGroupSpecifier 53 | 54 | 55 | StringsTable 56 | Acknowledgements 57 | Title 58 | Acknowledgements 59 | 60 | 61 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_WHKitDemo : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_WHKitDemo 5 | @end 6 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-Debug-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/WHKit/WHKit.framework -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-Debug-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WHKit.framework -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-Release-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/WHKit/WHKit.framework -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-Release-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WHKit.framework -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -u 4 | set -o pipefail 5 | 6 | function on_error { 7 | echo "$(realpath -mq "${0}"):$1: error: Unexpected failure" 8 | } 9 | trap 'on_error $LINENO' ERR 10 | 11 | if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then 12 | # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy 13 | # frameworks to, so exit 0 (signalling the script phase was successful). 14 | exit 0 15 | fi 16 | 17 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 18 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 19 | 20 | COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}" 21 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 22 | BCSYMBOLMAP_DIR="BCSymbolMaps" 23 | 24 | 25 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 26 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 27 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 28 | 29 | # Copies and strips a vendored framework 30 | install_framework() 31 | { 32 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 33 | local source="${BUILT_PRODUCTS_DIR}/$1" 34 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 35 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 36 | elif [ -r "$1" ]; then 37 | local source="$1" 38 | fi 39 | 40 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 41 | 42 | if [ -L "${source}" ]; then 43 | echo "Symlinked..." 44 | source="$(readlink "${source}")" 45 | fi 46 | 47 | if [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then 48 | # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied 49 | find "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; do 50 | echo "Installing $f" 51 | install_bcsymbolmap "$f" "$destination" 52 | rm "$f" 53 | done 54 | rmdir "${source}/${BCSYMBOLMAP_DIR}" 55 | fi 56 | 57 | # Use filter instead of exclude so missing patterns don't throw errors. 58 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 59 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 60 | 61 | local basename 62 | basename="$(basename -s .framework "$1")" 63 | binary="${destination}/${basename}.framework/${basename}" 64 | 65 | if ! [ -r "$binary" ]; then 66 | binary="${destination}/${basename}" 67 | elif [ -L "${binary}" ]; then 68 | echo "Destination binary is symlinked..." 69 | dirname="$(dirname "${binary}")" 70 | binary="${dirname}/$(readlink "${binary}")" 71 | fi 72 | 73 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 74 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 75 | strip_invalid_archs "$binary" 76 | fi 77 | 78 | # Resign the code if required by the build settings to avoid unstable apps 79 | code_sign_if_enabled "${destination}/$(basename "$1")" 80 | 81 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 82 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 83 | local swift_runtime_libs 84 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u) 85 | for lib in $swift_runtime_libs; do 86 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 87 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 88 | code_sign_if_enabled "${destination}/${lib}" 89 | done 90 | fi 91 | } 92 | # Copies and strips a vendored dSYM 93 | install_dsym() { 94 | local source="$1" 95 | warn_missing_arch=${2:-true} 96 | if [ -r "$source" ]; then 97 | # Copy the dSYM into the targets temp dir. 98 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" 99 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" 100 | 101 | local basename 102 | basename="$(basename -s .dSYM "$source")" 103 | binary_name="$(ls "$source/Contents/Resources/DWARF")" 104 | binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}" 105 | 106 | # Strip invalid architectures from the dSYM. 107 | if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then 108 | strip_invalid_archs "$binary" "$warn_missing_arch" 109 | fi 110 | if [[ $STRIP_BINARY_RETVAL == 0 ]]; then 111 | # Move the stripped file into its final destination. 112 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" 113 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.dSYM" "${DWARF_DSYM_FOLDER_PATH}" 114 | else 115 | # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. 116 | touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM" 117 | fi 118 | fi 119 | } 120 | 121 | # Used as a return value for each invocation of `strip_invalid_archs` function. 122 | STRIP_BINARY_RETVAL=0 123 | 124 | # Strip invalid architectures 125 | strip_invalid_archs() { 126 | binary="$1" 127 | warn_missing_arch=${2:-true} 128 | # Get architectures for current target binary 129 | binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" 130 | # Intersect them with the architectures we are building for 131 | intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" 132 | # If there are no archs supported by this binary then warn the user 133 | if [[ -z "$intersected_archs" ]]; then 134 | if [[ "$warn_missing_arch" == "true" ]]; then 135 | echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." 136 | fi 137 | STRIP_BINARY_RETVAL=1 138 | return 139 | fi 140 | stripped="" 141 | for arch in $binary_archs; do 142 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 143 | # Strip non-valid architectures in-place 144 | lipo -remove "$arch" -output "$binary" "$binary" 145 | stripped="$stripped $arch" 146 | fi 147 | done 148 | if [[ "$stripped" ]]; then 149 | echo "Stripped $binary of architectures:$stripped" 150 | fi 151 | STRIP_BINARY_RETVAL=0 152 | } 153 | 154 | # Copies the bcsymbolmap files of a vendored framework 155 | install_bcsymbolmap() { 156 | local bcsymbolmap_path="$1" 157 | local destination="${BUILT_PRODUCTS_DIR}" 158 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"" 159 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}" 160 | } 161 | 162 | # Signs a framework with the provided identity 163 | code_sign_if_enabled() { 164 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 165 | # Use the current code_sign_identity 166 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 167 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'" 168 | 169 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 170 | code_sign_cmd="$code_sign_cmd &" 171 | fi 172 | echo "$code_sign_cmd" 173 | eval "$code_sign_cmd" 174 | fi 175 | } 176 | 177 | if [[ "$CONFIGURATION" == "Debug" ]]; then 178 | install_framework "${BUILT_PRODUCTS_DIR}/WHKit/WHKit.framework" 179 | fi 180 | if [[ "$CONFIGURATION" == "Release" ]]; then 181 | install_framework "${BUILT_PRODUCTS_DIR}/WHKit/WHKit.framework" 182 | fi 183 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 184 | wait 185 | fi 186 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_WHKitDemoVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_WHKitDemoVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/WHKit" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/WHKit/WHKit.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" -framework "WHKit" 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 10 | PODS_ROOT = ${SRCROOT}/Pods 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_WHKitDemo { 2 | umbrella header "Pods-WHKitDemo-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/WHKit" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/WHKit/WHKit.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" -framework "WHKit" 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 10 | PODS_ROOT = ${SRCROOT}/Pods 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit-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 | FMWK 17 | CFBundleShortVersionString 18 | 1.8.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_WHKit : NSObject 3 | @end 4 | @implementation PodsDummy_WHKit 5 | @end 6 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | #import "CALayer+WHLayer.h" 14 | #import "Foundation+Safe.h" 15 | #import "NSArray+WHArray.h" 16 | #import "NSDate+WHDate.h" 17 | #import "NSDictionary+WHDictionary.h" 18 | #import "NSFileManager+WHFileManager.h" 19 | #import "NSNumber+WHNumber.h" 20 | #import "NSObject+WHObject.h" 21 | #import "NSObject+WHRuntime.h" 22 | #import "NSString+WHString.h" 23 | #import "NSTimer+WHTimer.h" 24 | #import "SerializeKit.h" 25 | #import "UIAlertController+WHAlert.h" 26 | #import "UIBarButtonItem+WHBarButtonItem.h" 27 | #import "UIButton+WHButton.h" 28 | #import "UIColor+WHColor.h" 29 | #import "UIDevice+WHDevice.h" 30 | #import "UIImage+WHImage.h" 31 | #import "UILabel+WHLabel.h" 32 | #import "UINavigationController+WHNavigationController.h" 33 | #import "UIScrollView+WHScrollView.h" 34 | #import "UITableView+WHTableView.h" 35 | #import "UIView+WHView.h" 36 | #import "UIViewController+WHVC.h" 37 | #import "WHKit.h" 38 | #import "WHMacro.h" 39 | #import "WHMethods.h" 40 | #import "WHSingleton.h" 41 | 42 | FOUNDATION_EXPORT double WHKitVersionNumber; 43 | FOUNDATION_EXPORT const unsigned char WHKitVersionString[]; 44 | 45 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/WHKit 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 9 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit.modulemap: -------------------------------------------------------------------------------- 1 | framework module WHKit { 2 | umbrella header "WHKit-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/WHKit 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 9 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /WHKitDemo/Pods/Target Support Files/WHKit/WHKit.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/WHKit 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | OTHER_LDFLAGS = $(inherited) -framework "UIKit" 4 | PODS_BUILD_DIR = ${BUILD_DIR} 5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT} 7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 51; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9B00A48824EFAFB200272E4F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B00A48724EFAFB200272E4F /* AppDelegate.m */; }; 11 | 9B00A48B24EFAFB200272E4F /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B00A48A24EFAFB200272E4F /* SceneDelegate.m */; }; 12 | 9B00A48E24EFAFB200272E4F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B00A48D24EFAFB200272E4F /* ViewController.m */; }; 13 | 9B00A49124EFAFB200272E4F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9B00A48F24EFAFB200272E4F /* Main.storyboard */; }; 14 | 9B00A49324EFAFB500272E4F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9B00A49224EFAFB500272E4F /* Assets.xcassets */; }; 15 | 9B00A49624EFAFB500272E4F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9B00A49424EFAFB500272E4F /* LaunchScreen.storyboard */; }; 16 | 9B00A49924EFAFB500272E4F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B00A49824EFAFB500272E4F /* main.m */; }; 17 | AC8791D2A67377949AAC34C4 /* Pods_WHKitDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F1558FB1154EAFA8BB8757D /* Pods_WHKitDemo.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 7F1558FB1154EAFA8BB8757D /* Pods_WHKitDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WHKitDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 941A6A9889FB0527E704127B /* Pods-WHKitDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WHKitDemo.release.xcconfig"; path = "Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo.release.xcconfig"; sourceTree = ""; }; 23 | 9B00A48324EFAFB200272E4F /* WHKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WHKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 9B00A48624EFAFB200272E4F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 9B00A48724EFAFB200272E4F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 9B00A48924EFAFB200272E4F /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = ""; }; 27 | 9B00A48A24EFAFB200272E4F /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = ""; }; 28 | 9B00A48C24EFAFB200272E4F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 29 | 9B00A48D24EFAFB200272E4F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 30 | 9B00A49024EFAFB200272E4F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 31 | 9B00A49224EFAFB500272E4F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 9B00A49524EFAFB500272E4F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | 9B00A49724EFAFB500272E4F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 9B00A49824EFAFB500272E4F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | C17E159BD94FEF8770DF2C16 /* Pods-WHKitDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WHKitDemo.debug.xcconfig"; path = "Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo.debug.xcconfig"; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 9B00A48024EFAFB200272E4F /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | AC8791D2A67377949AAC34C4 /* Pods_WHKitDemo.framework in Frameworks */, 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 40D5FB685F3D9D3C993F1CA9 /* Frameworks */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 7F1558FB1154EAFA8BB8757D /* Pods_WHKitDemo.framework */, 54 | ); 55 | name = Frameworks; 56 | sourceTree = ""; 57 | }; 58 | 9B00A47A24EFAFB200272E4F = { 59 | isa = PBXGroup; 60 | children = ( 61 | 9B00A48524EFAFB200272E4F /* WHKitDemo */, 62 | 9B00A48424EFAFB200272E4F /* Products */, 63 | C911A71CE0549F57FC5C2C28 /* Pods */, 64 | 40D5FB685F3D9D3C993F1CA9 /* Frameworks */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 9B00A48424EFAFB200272E4F /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 9B00A48324EFAFB200272E4F /* WHKitDemo.app */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | 9B00A48524EFAFB200272E4F /* WHKitDemo */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 9B00A48624EFAFB200272E4F /* AppDelegate.h */, 80 | 9B00A48724EFAFB200272E4F /* AppDelegate.m */, 81 | 9B00A48924EFAFB200272E4F /* SceneDelegate.h */, 82 | 9B00A48A24EFAFB200272E4F /* SceneDelegate.m */, 83 | 9B00A48C24EFAFB200272E4F /* ViewController.h */, 84 | 9B00A48D24EFAFB200272E4F /* ViewController.m */, 85 | 9B00A48F24EFAFB200272E4F /* Main.storyboard */, 86 | 9B00A49224EFAFB500272E4F /* Assets.xcassets */, 87 | 9B00A49424EFAFB500272E4F /* LaunchScreen.storyboard */, 88 | 9B00A49724EFAFB500272E4F /* Info.plist */, 89 | 9B00A49824EFAFB500272E4F /* main.m */, 90 | ); 91 | path = WHKitDemo; 92 | sourceTree = ""; 93 | }; 94 | C911A71CE0549F57FC5C2C28 /* Pods */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | C17E159BD94FEF8770DF2C16 /* Pods-WHKitDemo.debug.xcconfig */, 98 | 941A6A9889FB0527E704127B /* Pods-WHKitDemo.release.xcconfig */, 99 | ); 100 | path = Pods; 101 | sourceTree = ""; 102 | }; 103 | /* End PBXGroup section */ 104 | 105 | /* Begin PBXNativeTarget section */ 106 | 9B00A48224EFAFB200272E4F /* WHKitDemo */ = { 107 | isa = PBXNativeTarget; 108 | buildConfigurationList = 9B00A49C24EFAFB500272E4F /* Build configuration list for PBXNativeTarget "WHKitDemo" */; 109 | buildPhases = ( 110 | 65286A4B20C1D79AF667EA8F /* [CP] Check Pods Manifest.lock */, 111 | 9B00A47F24EFAFB200272E4F /* Sources */, 112 | 9B00A48024EFAFB200272E4F /* Frameworks */, 113 | 9B00A48124EFAFB200272E4F /* Resources */, 114 | E9AB0B1C8A486876390EF977 /* [CP] Embed Pods Frameworks */, 115 | ); 116 | buildRules = ( 117 | ); 118 | dependencies = ( 119 | ); 120 | name = WHKitDemo; 121 | productName = WHKitDemo; 122 | productReference = 9B00A48324EFAFB200272E4F /* WHKitDemo.app */; 123 | productType = "com.apple.product-type.application"; 124 | }; 125 | /* End PBXNativeTarget section */ 126 | 127 | /* Begin PBXProject section */ 128 | 9B00A47B24EFAFB200272E4F /* Project object */ = { 129 | isa = PBXProject; 130 | attributes = { 131 | LastUpgradeCheck = 1240; 132 | ORGANIZATIONNAME = wuhao; 133 | TargetAttributes = { 134 | 9B00A48224EFAFB200272E4F = { 135 | CreatedOnToolsVersion = 11.3.1; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 9B00A47E24EFAFB200272E4F /* Build configuration list for PBXProject "WHKitDemo" */; 140 | compatibilityVersion = "Xcode 9.3"; 141 | developmentRegion = en; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 9B00A47A24EFAFB200272E4F; 148 | productRefGroup = 9B00A48424EFAFB200272E4F /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 9B00A48224EFAFB200272E4F /* WHKitDemo */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 9B00A48124EFAFB200272E4F /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 9B00A49624EFAFB500272E4F /* LaunchScreen.storyboard in Resources */, 163 | 9B00A49324EFAFB500272E4F /* Assets.xcassets in Resources */, 164 | 9B00A49124EFAFB200272E4F /* Main.storyboard in Resources */, 165 | ); 166 | runOnlyForDeploymentPostprocessing = 0; 167 | }; 168 | /* End PBXResourcesBuildPhase section */ 169 | 170 | /* Begin PBXShellScriptBuildPhase section */ 171 | 65286A4B20C1D79AF667EA8F /* [CP] Check Pods Manifest.lock */ = { 172 | isa = PBXShellScriptBuildPhase; 173 | buildActionMask = 2147483647; 174 | files = ( 175 | ); 176 | inputFileListPaths = ( 177 | ); 178 | inputPaths = ( 179 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 180 | "${PODS_ROOT}/Manifest.lock", 181 | ); 182 | name = "[CP] Check Pods Manifest.lock"; 183 | outputFileListPaths = ( 184 | ); 185 | outputPaths = ( 186 | "$(DERIVED_FILE_DIR)/Pods-WHKitDemo-checkManifestLockResult.txt", 187 | ); 188 | runOnlyForDeploymentPostprocessing = 0; 189 | shellPath = /bin/sh; 190 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 191 | showEnvVarsInLog = 0; 192 | }; 193 | E9AB0B1C8A486876390EF977 /* [CP] Embed Pods Frameworks */ = { 194 | isa = PBXShellScriptBuildPhase; 195 | buildActionMask = 2147483647; 196 | files = ( 197 | ); 198 | inputFileListPaths = ( 199 | "${PODS_ROOT}/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-${CONFIGURATION}-input-files.xcfilelist", 200 | ); 201 | name = "[CP] Embed Pods Frameworks"; 202 | outputFileListPaths = ( 203 | "${PODS_ROOT}/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks-${CONFIGURATION}-output-files.xcfilelist", 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | shellPath = /bin/sh; 207 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WHKitDemo/Pods-WHKitDemo-frameworks.sh\"\n"; 208 | showEnvVarsInLog = 0; 209 | }; 210 | /* End PBXShellScriptBuildPhase section */ 211 | 212 | /* Begin PBXSourcesBuildPhase section */ 213 | 9B00A47F24EFAFB200272E4F /* Sources */ = { 214 | isa = PBXSourcesBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | 9B00A48E24EFAFB200272E4F /* ViewController.m in Sources */, 218 | 9B00A48824EFAFB200272E4F /* AppDelegate.m in Sources */, 219 | 9B00A49924EFAFB500272E4F /* main.m in Sources */, 220 | 9B00A48B24EFAFB200272E4F /* SceneDelegate.m in Sources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | /* End PBXSourcesBuildPhase section */ 225 | 226 | /* Begin PBXVariantGroup section */ 227 | 9B00A48F24EFAFB200272E4F /* Main.storyboard */ = { 228 | isa = PBXVariantGroup; 229 | children = ( 230 | 9B00A49024EFAFB200272E4F /* Base */, 231 | ); 232 | name = Main.storyboard; 233 | sourceTree = ""; 234 | }; 235 | 9B00A49424EFAFB500272E4F /* LaunchScreen.storyboard */ = { 236 | isa = PBXVariantGroup; 237 | children = ( 238 | 9B00A49524EFAFB500272E4F /* Base */, 239 | ); 240 | name = LaunchScreen.storyboard; 241 | sourceTree = ""; 242 | }; 243 | /* End PBXVariantGroup section */ 244 | 245 | /* Begin XCBuildConfiguration section */ 246 | 9B00A49A24EFAFB500272E4F /* Debug */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_ANALYZER_NONNULL = YES; 251 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_ENABLE_OBJC_WEAK = YES; 257 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 258 | CLANG_WARN_BOOL_CONVERSION = YES; 259 | CLANG_WARN_COMMA = YES; 260 | CLANG_WARN_CONSTANT_CONVERSION = YES; 261 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 262 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 263 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 264 | CLANG_WARN_EMPTY_BODY = YES; 265 | CLANG_WARN_ENUM_CONVERSION = YES; 266 | CLANG_WARN_INFINITE_RECURSION = YES; 267 | CLANG_WARN_INT_CONVERSION = YES; 268 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 269 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 270 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 271 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 272 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 273 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 274 | CLANG_WARN_STRICT_PROTOTYPES = YES; 275 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 276 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 277 | CLANG_WARN_UNREACHABLE_CODE = YES; 278 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 279 | COPY_PHASE_STRIP = NO; 280 | DEBUG_INFORMATION_FORMAT = dwarf; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | ENABLE_TESTABILITY = YES; 283 | GCC_C_LANGUAGE_STANDARD = gnu11; 284 | GCC_DYNAMIC_NO_PIC = NO; 285 | GCC_NO_COMMON_BLOCKS = YES; 286 | GCC_OPTIMIZATION_LEVEL = 0; 287 | GCC_PREPROCESSOR_DEFINITIONS = ( 288 | "DEBUG=1", 289 | "$(inherited)", 290 | ); 291 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 292 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 293 | GCC_WARN_UNDECLARED_SELECTOR = YES; 294 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 295 | GCC_WARN_UNUSED_FUNCTION = YES; 296 | GCC_WARN_UNUSED_VARIABLE = YES; 297 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 298 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 299 | MTL_FAST_MATH = YES; 300 | ONLY_ACTIVE_ARCH = YES; 301 | SDKROOT = iphoneos; 302 | }; 303 | name = Debug; 304 | }; 305 | 9B00A49B24EFAFB500272E4F /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_ANALYZER_NONNULL = YES; 310 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 311 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 312 | CLANG_CXX_LIBRARY = "libc++"; 313 | CLANG_ENABLE_MODULES = YES; 314 | CLANG_ENABLE_OBJC_ARC = YES; 315 | CLANG_ENABLE_OBJC_WEAK = YES; 316 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 317 | CLANG_WARN_BOOL_CONVERSION = YES; 318 | CLANG_WARN_COMMA = YES; 319 | CLANG_WARN_CONSTANT_CONVERSION = YES; 320 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 323 | CLANG_WARN_EMPTY_BODY = YES; 324 | CLANG_WARN_ENUM_CONVERSION = YES; 325 | CLANG_WARN_INFINITE_RECURSION = YES; 326 | CLANG_WARN_INT_CONVERSION = YES; 327 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 328 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 329 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 330 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 331 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 332 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 333 | CLANG_WARN_STRICT_PROTOTYPES = YES; 334 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 335 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 336 | CLANG_WARN_UNREACHABLE_CODE = YES; 337 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 338 | COPY_PHASE_STRIP = NO; 339 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 340 | ENABLE_NS_ASSERTIONS = NO; 341 | ENABLE_STRICT_OBJC_MSGSEND = YES; 342 | GCC_C_LANGUAGE_STANDARD = gnu11; 343 | GCC_NO_COMMON_BLOCKS = YES; 344 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 345 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 346 | GCC_WARN_UNDECLARED_SELECTOR = YES; 347 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 348 | GCC_WARN_UNUSED_FUNCTION = YES; 349 | GCC_WARN_UNUSED_VARIABLE = YES; 350 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 351 | MTL_ENABLE_DEBUG_INFO = NO; 352 | MTL_FAST_MATH = YES; 353 | SDKROOT = iphoneos; 354 | VALIDATE_PRODUCT = YES; 355 | }; 356 | name = Release; 357 | }; 358 | 9B00A49D24EFAFB500272E4F /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | baseConfigurationReference = C17E159BD94FEF8770DF2C16 /* Pods-WHKitDemo.debug.xcconfig */; 361 | buildSettings = { 362 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 363 | CODE_SIGN_STYLE = Automatic; 364 | INFOPLIST_FILE = WHKitDemo/Info.plist; 365 | LD_RUNPATH_SEARCH_PATHS = ( 366 | "$(inherited)", 367 | "@executable_path/Frameworks", 368 | ); 369 | PRODUCT_BUNDLE_IDENTIFIER = com.wuhao.WHKitDemo; 370 | PRODUCT_NAME = "$(TARGET_NAME)"; 371 | TARGETED_DEVICE_FAMILY = "1,2"; 372 | }; 373 | name = Debug; 374 | }; 375 | 9B00A49E24EFAFB500272E4F /* Release */ = { 376 | isa = XCBuildConfiguration; 377 | baseConfigurationReference = 941A6A9889FB0527E704127B /* Pods-WHKitDemo.release.xcconfig */; 378 | buildSettings = { 379 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 380 | CODE_SIGN_STYLE = Automatic; 381 | INFOPLIST_FILE = WHKitDemo/Info.plist; 382 | LD_RUNPATH_SEARCH_PATHS = ( 383 | "$(inherited)", 384 | "@executable_path/Frameworks", 385 | ); 386 | PRODUCT_BUNDLE_IDENTIFIER = com.wuhao.WHKitDemo; 387 | PRODUCT_NAME = "$(TARGET_NAME)"; 388 | TARGETED_DEVICE_FAMILY = "1,2"; 389 | }; 390 | name = Release; 391 | }; 392 | /* End XCBuildConfiguration section */ 393 | 394 | /* Begin XCConfigurationList section */ 395 | 9B00A47E24EFAFB200272E4F /* Build configuration list for PBXProject "WHKitDemo" */ = { 396 | isa = XCConfigurationList; 397 | buildConfigurations = ( 398 | 9B00A49A24EFAFB500272E4F /* Debug */, 399 | 9B00A49B24EFAFB500272E4F /* Release */, 400 | ); 401 | defaultConfigurationIsVisible = 0; 402 | defaultConfigurationName = Release; 403 | }; 404 | 9B00A49C24EFAFB500272E4F /* Build configuration list for PBXNativeTarget "WHKitDemo" */ = { 405 | isa = XCConfigurationList; 406 | buildConfigurations = ( 407 | 9B00A49D24EFAFB500272E4F /* Debug */, 408 | 9B00A49E24EFAFB500272E4F /* Release */, 409 | ); 410 | defaultConfigurationIsVisible = 0; 411 | defaultConfigurationName = Release; 412 | }; 413 | /* End XCConfigurationList section */ 414 | }; 415 | rootObject = 9B00A47B24EFAFB200272E4F /* Project object */; 416 | } 417 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. 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 | 24 | #pragma mark - UISceneSession lifecycle 25 | 26 | 27 | - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; 31 | } 32 | 33 | 34 | - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { 35 | // Called when the user discards a scene session. 36 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 37 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 38 | } 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/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 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/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 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/SceneDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.h 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SceneDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow * window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/SceneDelegate.m: -------------------------------------------------------------------------------- 1 | #import "SceneDelegate.h" 2 | 3 | @interface SceneDelegate () 4 | 5 | @end 6 | 7 | @implementation SceneDelegate 8 | 9 | 10 | - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { 11 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 12 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 13 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 14 | NSLog(@"scene window--->>>>%@", self.window); 15 | } 16 | 17 | 18 | - (void)sceneDidDisconnect:(UIScene *)scene { 19 | // Called as the scene is being released by the system. 20 | // This occurs shortly after the scene enters the background, or when its session is discarded. 21 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 22 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 23 | } 24 | 25 | 26 | - (void)sceneDidBecomeActive:(UIScene *)scene { 27 | // Called when the scene has moved from an inactive state to an active state. 28 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 29 | } 30 | 31 | 32 | - (void)sceneWillResignActive:(UIScene *)scene { 33 | // Called when the scene will move from an active state to an inactive state. 34 | // This may occur due to temporary interruptions (ex. an incoming phone call). 35 | } 36 | 37 | 38 | - (void)sceneWillEnterForeground:(UIScene *)scene { 39 | // Called as the scene transitions from the background to the foreground. 40 | // Use this method to undo the changes made on entering the background. 41 | } 42 | 43 | 44 | - (void)sceneDidEnterBackground:(UIScene *)scene { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WHKit.h" 11 | 12 | @implementation ViewController 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | // 本月的第一天距离现在多久 18 | NSLog(@"%@",[[NSDate begindayOfMonth:[NSDate new]] timeInfo]); 19 | 20 | // 定时器 21 | __block NSInteger test = 1; 22 | NSTimer *timer = [NSTimer wh_scheduledTimerWithTimeInterval:1 repeats:YES callback:^(NSTimer *timer) { 23 | NSLog(@"%ld",(test += 1)); 24 | }]; 25 | 26 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 27 | [timer pauseTimer]; // 暂停 28 | [timer resumeTimerAfterTimeInterval:5]; // 5秒后重新开启 29 | }); 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /WHKitDemo/WHKitDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WHKitDemo 4 | // 5 | // Created by wu, hao on 2020/8/21. 6 | // Copyright © 2020 wuhao. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | NSString * appDelegateClassName; 14 | @autoreleasepool { 15 | // Setup code that might create autoreleased objects goes here. 16 | appDelegateClassName = NSStringFromClass([AppDelegate class]); 17 | } 18 | return UIApplicationMain(argc, argv, nil, appDelegateClassName); 19 | } 20 | --------------------------------------------------------------------------------