-
Notifications
You must be signed in to change notification settings - Fork 2
/
FuASNode.m
168 lines (150 loc) · 6.38 KB
/
FuASNode.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
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
//
// FuASNode.m
// MiaoMiaoZheApp
//
// Created by 付海龙 on 2017/12/4.
// Copyright © 2017年 付海龙. All rights reserved.
//
#import "FuASNode.h"
#import "FuASYYWebImageManager.h"
@implementation ASDisplayNode (Public)
- (void)maskNodeBound:(CGFloat)borderWidth radius:(CGFloat)radius bordercolor:(UIColor *)borderColor
{
self.borderColor = [borderColor CGColor];
self.borderWidth = borderWidth;
self.cornerRadius = radius;
self.clipsToBounds = YES;
}
@end
@implementation ASTextNode (Public)
- (void)setAttributedString:(NSString *)string font:(UIFont *)font color:(UIColor *)color
{
[self setAttributedString:string font:font color:color subs:nil subColor:nil];
}
- (void)setAttributedString:(NSString *)string font:(UIFont *)font color:(UIColor *)color subs:(NSArray *)subsText subColor:(UIColor *)subColor
{
NSString *newString = IS_NOT_EMPTY(string)?string:@"";
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (color) {
[dict setObject:color forKey:NSForegroundColorAttributeName];
}
if (font) {
[dict setObject:font forKey:NSFontAttributeName];
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newString
attributes:dict
];
if (IS_NOT_EMPTY(newString) && subsText && subColor) {
for (id obj in subsText) {
NSString *oneStr = nil;
if ([obj isKindOfClass:[NSNumber class]]) {
oneStr = [NSString stringWithFormat:@"%@", obj];
}else if ([obj isKindOfClass:[NSString class]]) {
oneStr = obj;
}
if (IS_NOT_EMPTY(oneStr)) {
NSString *tmpStr = newString;
NSInteger index = 0;
while (1) {
if ([tmpStr containsString:oneStr]) {
NSRange range = [tmpStr rangeOfString:oneStr];
range.location += index;
if (range.location != NSNotFound) {
[attributedString addAttribute:NSForegroundColorAttributeName value:subColor range:range];
}
tmpStr = [newString substringFromIndex:range.location + range.length];
index += range.location + range.length;
}else {
break;
}
}
}
}
}
self.attributedText = attributedString;
}
- (void)setAttributedString:(NSString *)string font:(UIFont *)font color:(UIColor *)color lineSpace:(CGFloat)lineSpace kern:(CGFloat)kern textAlignment:(NSTextAlignment)textAlignment subs:(NSArray *)subsText subColor:(UIColor *)subColor
{
NSString *newString = IS_NOT_EMPTY(string)?string:@"";
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (color) {
[dict setObject:color forKey:NSForegroundColorAttributeName];
}
if (font) {
[dict setObject:font forKey:NSFontAttributeName];
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newString
attributes:dict
];
if (IS_NOT_EMPTY(newString) && subsText && subColor) {
for (id obj in subsText) {
NSString *oneStr = nil;
if ([obj isKindOfClass:[NSNumber class]]) {
oneStr = [NSString stringWithFormat:@"%@", obj];
}else if ([obj isKindOfClass:[NSString class]]) {
oneStr = obj;
}
if (IS_NOT_EMPTY(oneStr)) {
NSString *tmpStr = newString;
NSInteger index = 0;
while (1) {
if ([tmpStr containsString:oneStr]) {
NSRange range = [tmpStr rangeOfString:oneStr];
range.location += index;
if (range.location != NSNotFound) {
[attributedString addAttribute:NSForegroundColorAttributeName value:subColor range:range];
}
tmpStr = [newString substringFromIndex:range.location + range.length];
index += range.location + range.length;
}else {
break;
}
}
}
}
}
self.attributedText = attributedString;
}
@end
@implementation ASButtonNode (Public)
- (void)setAttributedString:(NSString *)string font:(UIFont *)font color:(UIColor *)color forState:(UIControlState)state
{
NSString *newString = IS_NOT_EMPTY(string)?string:@"";
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (color) {
[dict setObject:color forKey:NSForegroundColorAttributeName];
}
if (font) {
[dict setObject:font forKey:NSFontAttributeName];
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newString
attributes:dict
];
[self setAttributedTitle:attributedString forState:state];
}
@end
@implementation ASNetworkImageNode (Public)
+ (id)imageNode
{
YYWebImageManager *manager = [YYWebImageManager sharedManager];
ASNetworkImageNode *node = [[ASNetworkImageNode alloc] initWithCache:manager downloader:manager];
return node;
}
- (void)setUrlStr:(NSString *)urlString placeholderImage:(UIImage *)placeholderImage
{
if ([urlString containsString:@","] && [urlString containsString:@"base64"]) {
NSString *dataStr = [[urlString componentsSeparatedByString:@","] lastObject];
NSData *imgData = [[NSData alloc] initWithBase64EncodedString:dataStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
self.image = [UIImage imageWithData:imgData];
}else {
NSURL *url = [NSURL URLWithString:urlString];
if (placeholderImage) {
self.defaultImage = placeholderImage;
}
self.placeholderEnabled = NO;
// self.placeholderColor = THEME_COLOR;
// self.placeholderFadeDuration = 3;
self.URL = url;
}
}
@end