@@ -42,11 +42,13 @@ - (UITextView *)contentTextView
42
42
{
43
43
if (!_contentTextView) {
44
44
_contentTextView = [[UITextView alloc ]init];
45
- _contentTextView.textContainerInset = UIEdgeInsetsMake (1 , 1 , 1 , 1 );
45
+ _contentTextView.textContainerInset = UIEdgeInsetsMake (1 ,1 ,1 ,1 );
46
+ // _contentTextView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
46
47
_contentTextView.editable = NO ;
47
48
_contentTextView.userInteractionEnabled = NO ;
48
49
_contentTextView.scrollEnabled = NO ;
49
50
_contentTextView.backgroundColor = [UIColor clearColor ];
51
+ _contentTextView.textAlignment = NSTextAlignmentLeft;
50
52
}
51
53
return _contentTextView;
52
54
}
@@ -148,10 +150,6 @@ - (void)layoutSubviews
148
150
{
149
151
[super layoutSubviews ];
150
152
self.contentTextView .frame = self.bounds ;
151
- if (_keywordConfig) return ;
152
- // 设置高亮关键字
153
- [self keyWord: [[NSMutableAttributedString alloc ]initWithAttributedString:self .contentTextView.attributedText]];
154
- _keywordConfig = YES ;
155
153
}
156
154
157
155
@@ -162,6 +160,9 @@ - (void)setText:(NSString *)text customLinks:(NSArray<NSString *> *)customLinks
162
160
_text = text;
163
161
_customLinks = customLinks;
164
162
_keywords = keywords;
163
+
164
+ // 渲染
165
+ [self render ];
165
166
}
166
167
167
168
#pragma mark - 添加指定区间链接 , 公共接口
@@ -170,6 +171,9 @@ - (void)setText:(NSString *)text linkRanges:(NSArray<NSValue *> *) ranges keywor
170
171
_text = text;
171
172
_keywords = keywords;
172
173
_linkranges = ranges;
174
+
175
+ // 渲染
176
+ [self render ];
173
177
}
174
178
175
179
#pragma mark - 开始渲染
@@ -180,6 +184,13 @@ - (void)render
180
184
// 复用处理
181
185
[self reuseHandle ];
182
186
[self configAttribute: _text];
187
+
188
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.00001 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
189
+ if (_keywordConfig) return ;
190
+ // 设置高亮关键字
191
+ [self keyWord: [[NSMutableAttributedString alloc ]initWithAttributedString:self .contentTextView.attributedText]];
192
+ _keywordConfig = YES ;
193
+ });
183
194
}
184
195
185
196
#pragma mark - 配置属性
@@ -546,9 +557,6 @@ - (void)judge
546
557
#pragma mark - 计算尺寸
547
558
- (CGSize)sizeThatFits : (CGSize)size
548
559
{
549
- // 渲染
550
- [self render ];
551
-
552
560
if (!self.contentTextView .attributedText .length ) {
553
561
return CGSizeZero;
554
562
}
0 commit comments