-
Notifications
You must be signed in to change notification settings - Fork 1
/
SnailUtil.m
99 lines (75 loc) · 2.82 KB
/
SnailUtil.m
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
//
// SnailUtil.m
// YingKeBao
//
// Created by JobNewMac1 on 2018/6/21.
// Copyright © 2018年 com.jonnew. All rights reserved.
//
#import "SnailUtil.h"
NSString * const kSUCSIEText = @"SnailUtilCheckStringIsEmptyText";
NSString * const kSUCSIEError = @"SnailUtilCheckStringIsEmptyError";
@implementation SnailUtil
+ (UIViewController *)takeVCOfView:(UIView *)view {
UIViewController *vc;
UIResponder *respon;
while ((respon = [view nextResponder])) {
if ([respon isKindOfClass:[UIViewController class]]) {
vc = (UIViewController *)respon;
break;
};
}
return vc;
}
+ (NSString *)checkStringIsEmpty:(NSArray<NSDictionary<NSString *,NSString *> *> *)targets {
for (NSDictionary *dic in targets) {
if ([dic[kSUCSIEText] length] == 0) {
return dic[kSUCSIEError];
}
}
return nil;
}
+(UIViewController *)takeTopController {
UIViewController *resultVC;
resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
while (resultVC.presentedViewController) {
resultVC = [self _topViewController:resultVC.presentedViewController];
}
return resultVC;
}
+ (UIViewController *)_topViewController:(UIViewController *)vc {
if ([vc isKindOfClass:[UINavigationController class]]) {
return [self _topViewController:[(UINavigationController *)vc topViewController]];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
} else {
return vc;
}
return nil;
}
+ (NSString *)takeCurrencySymbol {
NSLocale *locale = [NSLocale currentLocale];
return [locale objectForKey:NSLocaleCurrencySymbol];
}
+ (UIImage *)takeCycleMaskImage:(CGSize)size :(UIColor *)cycleColor :(UIColor *)otherColor {
if (cycleColor == nil) {
cycleColor = SNA_CLEAR_COLOR;
}
if (otherColor == nil) {
otherColor = SNA_CLEAR_COLOR;
}
NSString *name = [NSString stringWithFormat:@"圆形遮罩%@%@%@",NSStringFromCGSize(size),cycleColor.snail_ColorToHexString,otherColor.snail_ColorToHexString];
UIImage *tmp = [SnailSimpleCIMManager takeCIM:name Cache:true Size:^CGSize{
return size;
} Block:^(CGContextRef ctx, CGRect rect, CGFloat scale) {
[cycleColor setFill];
CGContextFillRect(ctx, rect);
UIBezierPath *path0 = [UIBezierPath bezierPathWithRect:rect];
CGContextAddPath(ctx, path0.CGPath);
UIBezierPath *path1 = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height * .5];
CGContextAddPath(ctx, path1.CGPath);
[otherColor setFill];
CGContextEOFillPath(ctx);
}];
return tmp;
}
@end