YHAssistant.h
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//
// YHAssistant.h
// YOHOBoard
//
// Created by Louis Zhu on 12-7-19.
// Copyright (c) 2012年 NewPower Co.. All rights reserved.
//
#define kScreenScale ([UIScreen instancesRespondToSelector:@selector(scale)]?[[UIScreen mainScreen] scale]:(1.0f))
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
//for gif with SDWebImage
//#import "SDWebImageCompat.h"
//#import "SDWebImageManager.h"
extern void yh_dispatch_execute_in_worker_queue(dispatch_block_t block);
extern void yh_dispatch_execute_in_main_queue(dispatch_block_t block);
extern void yh_dispatch_execute_in_main_queue_after(int64_t delay, dispatch_block_t block);
extern BOOL yh_option_contains_bit(NSUInteger option, NSUInteger bit);
typedef NS_ENUM(NSInteger, YHAlertType) {
YHAlertTypeFail,
YHAlertTypeSuccess,
YHAlertTypeNetwork,
};
static NSString * const YHEAPIErrorDomain = @"YHEAPIErrorDomain";
typedef NS_ENUM(NSInteger, YHEFollowerAndFollowingStatus){
YHEFollowerAndFollowingStatusUnFollower = 0,
YHEFollowerAndFollowingStatusFollowing,
YHEFollowerAndFollowingStatusMutualFollowed,
};
typedef NS_ENUM(NSInteger, YHEMasterType){
YHEMasterTypeNormal,
YHEMasterTypeV,
YHEMasterTypeStar,
YHEMasterTypeBrand
};
@interface UIFont (YOHO)
+ (UIFont *)m16_appENFontWithSize:(CGFloat)fontSize;
+ (UIFont *)m16_appCNFontWithSize:(CGFloat)fontSize;
+ (UIFont *)m16_navigationTitleFont;
+ (UIFont *)m16_appPageContainerChannelTitleFont;
+ (UIFont *)fontOfSCWithSize:(CGFloat)fontSize;
+ (UIFont *)fontOfTradeGothicLTStdWithSize:(CGFloat)fontSize;
+ (UIFont *)fontOfENWithSize:(CGFloat)fontSize;
+ (UIFont *)fontByCurrentLanguageWithSize:(CGFloat)fontSize;
+ (UIFont *)fontOfLightWithSize:(CGFloat)fontSize;
+ (UIFont *)fontOfSCHeiTiWithSize:(CGFloat)fontSize;
/**
@brief 指定大小的黑体字体
@param size 文字大小
@return 字体对象
@since 4.0.0
*/
+ (UIFont *)m16_blackfaceFontOfSize:(CGFloat)size;
@end
@interface NSObject (YOHO)
- (BOOL)notNilOrEmpty;
@end
@interface NSString (YOHO)
- (NSString *)md5String;
- (BOOL)isEmptyAfterTrimmingWhitespaceAndNewlineCharacters;
- (NSString *)stringByTrimmingWhitespaceAndNewlineCharacters;
// 是否是邮箱
- (BOOL)conformsToEMailFormat;
// 长度是否在一个范围之内,包括范围值
- (BOOL)isLengthGreaterThanOrEqual:(NSInteger)minimum lessThanOrEqual:(NSInteger)maximum;
- (NSRange)firstRangeOfURLSubstring;
- (NSString *)firstURLSubstring;
- (NSArray *)URLSubstrings;
- (NSString *)firstMatchUsingRegularExpression:(NSRegularExpression *)regularExpression;
- (NSString *)firstMatchUsingRegularExpressionPattern:(NSString *)regularExpressionPattern;
// 注意这个是全文匹配
- (BOOL)matchesRegularExpressionPattern:(NSString *)regularExpressionPattern;
- (NSRange)rangeOfFirstMatchUsingRegularExpressionPattern:(NSString *)regularExpressionPattern;
- (NSString *)stringByReplacingMatchesUsingRegularExpressionPattern:(NSString *)regularExpressionPattern withTemplate:(NSString *)templ;
- (NSDictionary *)URLParameters;
+ (NSString *)stringWithDate:(NSDate *)date dateFormat:(NSString *)format;
// iOS7出了新的计算字符大小的方法,这里封装一下顺便少写一些参数,当然也只能算出一行的
- (CGFloat)singleLineWidthWithFont:(UIFont *)font;
- (CGFloat)singleLineHeightWithFont:(UIFont *)font;
- (CGFloat)heightWithFont:(UIFont *)font constrainedToWidth:(CGFloat)width;
- (NSRange)fullRange;
- (NSString *)stringToImageAdaptorScreen;
- (BOOL)validateTextIsPhoneNum;
- (BOOL)validateTextIsEmailAddress;
// 长度是否在一个范围之内
- (BOOL)isLenghGreaterThanOrEqual:(NSInteger)minimum lessThanOrEqual:(NSInteger)maximum;
/**
@brief 图片链接处理,自定义宽高,切图模式固定
@param width 期望图片宽度
@param height 期望图片高度
@return 图片url
@since 3.1
*/
- (NSString *)splitUrlWithWidth:(NSString *)width height:(NSString *)height;
@end
@interface NSMutableString (YOHO)
/**
@brief 截取两个字符串之间的字符,其中不含起始字符和结束字符
@param beginstr 起始字符
@param endstr 结束字符
@param text 要进行遍历的目标字符
@return BeginStr和endstr之间的字符,其中不含起始字符和结束字符
@since 4.0.4
*/
- (NSArray *)scanBeginStr:(NSString *)beginstr endStr:(NSString *)endstr;
@end
@interface NSArray (YOHO)
- (NSArray *)arrayWithObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate;
- (NSArray *)arrayByRemovingObjectsOfClass:(Class)aClass;
- (NSArray *)arrayByKeepingObjectsOfClass:(Class)aClass;
- (NSArray *)arrayByRemovingObjectsFromArray:(NSArray *)otherArray;
- (NSArray *)transformedArrayUsingHandler:(id (^)(id originalObject, NSUInteger index))handler;
@end
@interface NSMutableArray (YOHO)
+ (NSMutableArray *)nullArrayWithCapacity:(NSUInteger)capacity;
- (void)removeObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate;
- (void)removeLatterObjectsToKeepObjectsNoMoreThan:(NSInteger)maxCount;
- (void)replaceObject:(id)anObject withObject:(id)anotherObject;
- (void)insertUniqueObject:(id)anObject;
- (void)insertUniqueObject:(id)anObject atIndex:(NSInteger)index;
- (void)insertUniqueObjectsFromArray:(NSArray *)otherArray;
- (void)appendUniqueObjectsFromArray:(NSArray *)otherArray;
@end
@interface NSDictionary (YOHO)
- (NSMutableDictionary *)mutableDeepCopy;
- (NSString *)stringRepresentationByURLEncoding;
- (NSString *)stringForKey:(id)key;
- (NSDate *)dateForKey:(id)key;
- (NSInteger)integerForKey:(id)key;
@end
@interface UIColor (YOHO)
+ (UIColor *)colorWithIntegerRed:(NSInteger)r green:(NSInteger)g blue:(NSInteger)b;
+ (UIColor *)colorWithHexString:(NSString *)string;
@end
@interface UIImage (YOHO)
// 如果参数比原image的size小,是截取原image相应的rect里的部分,如果参数比原image大,则是白底填充原image
- (UIImage *)imageInRect:(CGRect)aRect;
- (UIImage *)centerSquareImage;
- (UIImage *) maskWithImage:(const UIImage *) maskImage;//使用maskImage遮罩原来图片
- (UIImage *)imageScaledToFitUploadSize;
- (UIImage *)scaledToFitSize:(CGSize)size;
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile compress:(BOOL)compress;
- (BOOL)writeToFile:(NSString *)path quality:(CGFloat)quality atomically:(BOOL)useAuxiliaryFile compress:(BOOL)compress;
- (UIImage *)fixOrientation;
+ (UIImage *)retina4CompatibleImageNamed:(NSString *)imageName;
+ (UIImage *)patternImageWithColor:(UIColor *)color;
@end
@interface UIView (YOHO)
- (void)removeAllSubviews;
- (void)addSubviews:(NSArray *)sb;
- (void)addAlwaysFitSubview:(UIView *)subview;
- (CGFloat)height;
- (CGFloat)width;
- (void)setOrigin:(CGPoint)origin;
- (void)setSize:(CGSize)size;
- (void)setX:(CGFloat)x;
- (void)setY:(CGFloat)y;
- (void)setWidth:(CGFloat)width;
- (void)setHeight:(CGFloat)height;
- (void)alert:(NSString *)message type:(YHAlertType)type;
- (void)alert:(NSString *)message type:(YHAlertType)type completion:(dispatch_block_t)completion;
- (void)alertNetwork;
- (void)alertDataError;
- (void)showWait;
- (void)hideWait;
@end
@interface UIImageView (YOHO)
+ (id)imageViewWithImageName:(NSString *)imageName;
//- (void)sd_setFLAnimationImageWithUrl:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageDownloaderCompletedBlock)completeBlock;
//
//- (void)sd_setFLAnimationImageWithUrl:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
@end
@interface UILabel (YOHO)
- (void)setFontSize:(NSInteger)size;
- (void)setTextWithDate:(NSDate *)date dateFormat:(NSString *)format;
- (CGFloat)adjustHeightWithText:(NSString *)text constrainedToLineCount:(NSUInteger)maxLineCount;
- (CGFloat)setText:(NSString *)text constrainedToLineCount:(NSUInteger)maxLineCount;
- (void)setText:(NSString *)text constrainedToLineCount:(NSUInteger)maxLineCount constrained:(BOOL *)constrained;
@end
@interface UIButton (YOHO)
+ (id)buttonWithImageName:(NSString *)imageName highlightedImageName:(NSString *)highlightedImageName title:(NSString *)title target:(id)target action:(SEL)action;
@end
@interface UITextField (YOHO)
- (BOOL)isEmptyAfterTrimmingWhitespaceAndNewlineCharacters;
@end
@interface UIViewController (YOHO)
- (void)popWithAnimation;
- (void)dismissModalViewControllerWithAnimation;
- (void)pushViewController:(UIViewController *)viewController;
@end
@interface UITextView (YOHO)
- (BOOL)isEmptyAfterTrimmingWhitespaceAndNewlineCharacters;
@end
@interface UIBarButtonItem (YOHO)
+ (id)itemWithImageName:(NSString *)imageName highlightedImageName:(NSString *)highlightedImageName title:(NSString *)title target:(id)target action:(SEL)action;
+ (id)itemWithImageName:(NSString *)imageName highlightedImageName:(NSString *)highlightedImageName title:(NSString *)title titleColor:(UIColor *)titleColor target:(id)target action:(SEL)action;
+ (id)smallItemWithImageName:(NSString *)imageName highlightedImageName:(NSString *)highlightedImageName title:(NSString *)title target:(id)target action:(SEL)action;
@end
@interface NSDate (YOHO)
//若format为nil ,默认为 yyyy.MM.dd HH: mm: ss 格式
- (NSString *)stringRepresentationWithDateFormat:(NSString *)format;
@end
@interface NSData (YOHO)
- (NSString *)md5Data;
@end
//@interface MBProgressHUD (YOHO)
//
//+ (MBProgressHUD *)alertMessage:(NSString *)aMessage addedTo:(UIView *)view animated:(BOOL)animated;
//+ (MBProgressHUD *)alertMessage:(NSString *)aMessage withDuration:(double)duration addedTo:(UIView *)view animated:(BOOL)animated;
//
//@end
@interface UITableView (YOHO)
- (NSIndexPath *)lastIndexPath;
- (void)scrollToLastRowAnimated:(BOOL)animated;
- (BOOL)lastCellVisible;
// 没有内容的后面也没有线条
- (void)hideTail;
- (BOOL)lastSetSectionVisible:(NSInteger)sectionIndex;
- (BOOL)lastSetRowVisible:(NSInteger)rowsIndex;
- (BOOL)lessOrContainVisibleLastSection:(NSInteger)SectionIndex;
/**
* 判断tableView是否已经滚动超过指定的行数,适用于只有一个section时
*
* @param rowsIndex 指定的tableView行数
*
* @return BOOL值
*/
- (BOOL)moreOrContainVisibleLastRows:(NSInteger)rowsIndex;
- (BOOL)lastSetSectionVisible:(NSInteger)sectionIndex lastIndex:(NSInteger)lastIndex;
@end
@interface UICollectionView (YOHO)
- (NSIndexPath *)lastIndexPath;
- (BOOL)lastCellVisible;
/**
* 确认第多少行cell是否可以访问,只能用于collectionView的layout是UICollectionViewFlowLayout时
*
* @return 返回倒数第几行的cell是否可见
*/
- (BOOL)backwordsFiveCellVisible;
@end
@interface NSFileManager (YOHO)
+ (void)setExcludedFromBackup:(BOOL)excluded forFileAtPath:(NSString *)path;
- (unsigned long long int)documentsFolderSize:(NSString *)documentPath;
- (void)removeFileAtPath:(NSString *)path condition:(BOOL (^)(NSString *))block;
+ (void)removeItemIfExistsAtPath:(NSString *)path error:(NSError **)error;
@end
@interface UIApplication (YOHO)
- (void)startYOHOPush;
- (void)clearNotificationMark;
@end
@interface UIBarButtonItem (YOHOE)
+ (instancetype)borderedBarButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action;
+ (instancetype)yheBarButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action hasBorder:(BOOL)hasBorder;
@end