Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54e3cb7

Browse files
committed
复用bug修复
1 parent 0eec833 commit 54e3cb7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

‎MYCoreText_Example/Controllers(各个场景使用说明)/KeywordViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (MYCoreTextLabel *)coretextLabel
2525
_coretextLabel.textFont = [UIFont systemFontOfSize:14.f]; //设置文本大小
2626
_coretextLabel.textColor = [UIColor brownColor]; // 设置文本颜色
2727
_coretextLabel.lineSpacing = 2; //设置行间距
28-
_coretextLabel.wordSpacing = 1.5; //设置字间距
28+
// _coretextLabel.wordSpacing = 1.5; //设置字间距
2929

3030

3131
//设置关键字属性

‎MYCoreText_Example/MYCoreTextLabel/MYCoreTextLabel.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ - (UITextView *)contentTextView
4242
{
4343
if (!_contentTextView) {
4444
_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);
4647
_contentTextView.editable = NO;
4748
_contentTextView.userInteractionEnabled = NO;
4849
_contentTextView.scrollEnabled = NO;
4950
_contentTextView.backgroundColor = [UIColor clearColor];
51+
_contentTextView.textAlignment = NSTextAlignmentLeft;
5052
}
5153
return _contentTextView;
5254
}
@@ -148,10 +150,6 @@ - (void)layoutSubviews
148150
{
149151
[super layoutSubviews];
150152
self.contentTextView.frame = self.bounds;
151-
if (_keywordConfig) return;
152-
//设置高亮关键字
153-
[self keyWord:[[NSMutableAttributedString alloc]initWithAttributedString:self.contentTextView.attributedText]];
154-
_keywordConfig = YES;
155153
}
156154

157155

@@ -162,6 +160,9 @@ - (void)setText:(NSString *)text customLinks:(NSArray<NSString *> *)customLinks
162160
_text = text;
163161
_customLinks = customLinks;
164162
_keywords = keywords;
163+
164+
//渲染
165+
[self render];
165166
}
166167

167168
#pragma mark - 添加指定区间链接 , 公共接口
@@ -170,6 +171,9 @@ - (void)setText:(NSString *)text linkRanges:(NSArray<NSValue *> *) ranges keywor
170171
_text = text;
171172
_keywords = keywords;
172173
_linkranges = ranges;
174+
175+
//渲染
176+
[self render];
173177
}
174178

175179
#pragma mark - 开始渲染
@@ -180,6 +184,13 @@ - (void)render
180184
//复用处理
181185
[self reuseHandle];
182186
[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+
});
183194
}
184195

185196
#pragma mark - 配置属性
@@ -546,9 +557,6 @@ - (void)judge
546557
#pragma mark - 计算尺寸
547558
- (CGSize)sizeThatFits:(CGSize)size
548559
{
549-
//渲染
550-
[self render];
551-
552560
if (!self.contentTextView.attributedText.length) {
553561
return CGSizeZero;
554562
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /