Skip to content

Commit

Permalink
Merge pull request #27 from molon/molon
Browse files Browse the repository at this point in the history
背景色绘制忽略省略字符串高度的实现优化
  • Loading branch information
molon committed Nov 4, 2015
2 parents ff848f5 + 6dded76 commit f2fd7cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Classes/Helper/MLLabelLayoutManager.m
Expand Up @@ -51,8 +51,14 @@ - (void)fillBackgroundRectArray:(const CGRect *)rectArray count:(NSUInteger)rect
NSRange glyphRangeInLine = NSIntersectionRange(glyphRange,lineRange);
NSRange truncatedGlyphRange = [self truncatedGlyphRangeInLineFragmentForGlyphAtIndex:glyphRangeInLine.location];
if (truncatedGlyphRange.location!=NSNotFound) {
//这里的glyphRangeInLine本身会带有被省略的区间,而我们下面计算最大行高和最小drawY的实现是不需要考虑省略的区间的,否则也可能计算有误。所以这里我们给过滤掉
glyphRangeInLine = NSMakeRange(glyphRangeInLine.location, truncatedGlyphRange.location-glyphRangeInLine.location);
//这里的glyphRangeInLine本身可能会带有被省略的区间,而我们下面计算最大行高和最小drawY的实现是不需要考虑省略的区间的,否则也可能计算有误。所以这里我们给过滤掉
NSRange sameRange = NSIntersectionRange(glyphRangeInLine, truncatedGlyphRange);
if (sameRange.length>0&&NSMaxRange(sameRange)==NSMaxRange(glyphRangeInLine)) {
//我们这里先只处理tail模式的
//而经过测试truncatedGlyphRangeInLineFragmentForGlyphAtIndex暂时只支持NSLineBreakByTruncatingTail模式
//其他两种暂时也不会用,即使用,现在通过TextKit的话也没法获取
glyphRangeInLine = NSMakeRange(glyphRangeInLine.location, sameRange.location-glyphRangeInLine.location);
}
}

if (glyphRangeInLine.length>0) {
Expand Down
5 changes: 5 additions & 0 deletions Example/MLLabel/ViewControllers/LinkViewController.m
Expand Up @@ -59,6 +59,11 @@ - (void)changeToResult:(int)result
}];

if (result==0) {
self.label.text = @"人生若只如初见,何事秋风悲画扇。等闲变却故人心,http://baidu.com却😷😷😷😷http://baidu.com道故人心易变。骊山语罢清宵半,泪雨零铃终不怨。http://baidu.com😷😷😷😷";
self.label.frameWidth = self.view.frameWidth-10.0f*2;
self.label.frameHeight = 60.0f;
self.label.lineBreakMode = NSLineBreakByTruncatingTail;
return;
}else if (result==1) {
//测试绘制背景色不会受到行间距设置的影响
self.label.lineHeightMultiple = 1.5f;
Expand Down

0 comments on commit f2fd7cb

Please sign in to comment.