Skip to content

Commit afd49b4

Browse files
author
amao
committed
version 1.8.0
1 parent f9c95cf commit afd49b4

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

M80AttributedLabel.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'M80AttributedLabel'
3-
s.version = '1.7.2'
3+
s.version = '1.8.0'
44
s.authors = {'Xiang Wangfeng' => 'xiangwangfeng@gmail.com'}
55
s.homepage = 'https://github.com/xiangwangfeng/M80AttributedLabel/'
66
s.summary = 'Another attributed label using CoreText'

M80AttributedLabel/M80AttributedLabel.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ - (CGRect)rectForRange:(NSRange)range
461461
CFArrayRef runs = CTLineGetGlyphRuns(line);
462462
CFIndex runCount = CFArrayGetCount(runs);
463463

464-
// Iterate through each of the "runs" (i.e. a chunk of text) and find the runs that
465-
// intersect with the range.
466464
for (CFIndex k = 0; k < runCount; k++)
467465
{
468466
CTRunRef run = CFArrayGetValueAtIndex(runs, k);
@@ -473,20 +471,18 @@ - (CGRect)rectForRange:(NSRange)range
473471

474472
if (intersectedRunRange.length == 0)
475473
{
476-
// This run doesn't intersect the range, so skip it.
477474
continue;
478475
}
479476

480477
CGFloat ascent = 0.0f;
481478
CGFloat descent = 0.0f;
482479
CGFloat leading = 0.0f;
483480

484-
// Use of 'leading' doesn't properly highlight Japanese-character link.
485481
CGFloat width = (CGFloat)CTRunGetTypographicBounds(run,
486482
CFRangeMake(0, 0),
487483
&ascent,
488484
&descent,
489-
NULL); //&leading);
485+
NULL);
490486
CGFloat height = ascent + descent;
491487

492488
CGFloat xOffset = CTLineGetOffsetForStringIndex(line, CTRunGetStringRange(run).location, nil);
@@ -768,6 +764,7 @@ - (void)drawHighlightWithRect:(CGRect)rect
768764
CGRect highlightRect = [self rectForRange:linkRange
769765
inLine:line
770766
lineOrigin:lineOrigins[i]];
767+
771768
highlightRect = CGRectOffset(highlightRect, 0, -rect.origin.y);
772769
if (!CGRectIsEmpty(highlightRect))
773770
{
@@ -844,7 +841,8 @@ - (void)drawText:(NSAttributedString *)attributedString
844841

845842
if (lastLineRange.length > 0)
846843
{
847-
//移除掉最后一个对象...(其实这个地方有点问题,也有可能需要移除最后 2 个对象,因为 attachment 宽度的关系)
844+
//移除掉最后一个对象...
845+
//其实这个地方有点问题,也有可能需要移除最后 2 个对象,因为 attachment 宽度的关系
848846
[truncationString deleteCharactersInRange:NSMakeRange(lastLineRange.length - 1, 1)];
849847
}
850848
[truncationString appendAttributedString:tokenString];
@@ -909,7 +907,7 @@ - (void)drawAttachments
909907
CGFloat lineHeight = lineAscent + lineDescent;
910908
CGFloat lineBottomY = lineOrigin.y - lineDescent;
911909

912-
//遍历以找到对应的 attachment 进行绘制
910+
//遍历找到对应的 attachment 进行绘制
913911
for (CFIndex k = 0; k < runCount; k++)
914912
{
915913
CTRunRef run = CFArrayGetValueAtIndex(runs, k);

M80AttributedLabel/M80AttributedLabelURL.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ + (NSDataDetector *)linkDetector
6262
NSDataDetector *detector = dict[M80LinkDetectorKey];
6363
if (detector == nil)
6464
{
65-
6665
detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber
6766
error:nil];
68-
dict[M80LinkDetectorKey] = detector;
67+
if (detector)
68+
{
69+
dict[M80LinkDetectorKey] = detector;
70+
}
6971
}
7072
return detector;
7173
}

0 commit comments

Comments
 (0)