Skip to content

Commit 33c2ff9

Browse files
committed
优化UILabel点击计算, 修复换行符问题
1 parent 606c361 commit 33c2ff9

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

AttributedString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "AttributedString"
4-
s.version = "1.6.7"
4+
s.version = "1.6.8"
55
s.summary = "基于Swift字符串插值快速构建你想要的富文本, 支持点击按住等事件获取, 支持多种类型过滤"
66

77
s.homepage = "https://github.com/lixiang1994/AttributedString"

AttributedString.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@
838838
"@executable_path/Frameworks",
839839
"@loader_path/Frameworks",
840840
);
841-
MARKETING_VERSION = 1.6.7;
841+
MARKETING_VERSION = 1.6.8;
842842
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.watchos;
843843
PRODUCT_NAME = AttributedString;
844844
SDKROOT = watchos;
@@ -866,7 +866,7 @@
866866
"@executable_path/Frameworks",
867867
"@loader_path/Frameworks",
868868
);
869-
MARKETING_VERSION = 1.6.7;
869+
MARKETING_VERSION = 1.6.8;
870870
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.watchos;
871871
PRODUCT_NAME = AttributedString;
872872
SDKROOT = watchos;
@@ -893,7 +893,7 @@
893893
"@executable_path/Frameworks",
894894
"@loader_path/Frameworks",
895895
);
896-
MARKETING_VERSION = 1.6.7;
896+
MARKETING_VERSION = 1.6.8;
897897
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.tvos;
898898
PRODUCT_NAME = AttributedString;
899899
SDKROOT = appletvos;
@@ -920,7 +920,7 @@
920920
"@executable_path/Frameworks",
921921
"@loader_path/Frameworks",
922922
);
923-
MARKETING_VERSION = 1.6.7;
923+
MARKETING_VERSION = 1.6.8;
924924
PRODUCT_BUNDLE_IDENTIFIER = com.attributedstring.tvos;
925925
PRODUCT_NAME = AttributedString;
926926
SDKROOT = appletvos;
@@ -996,7 +996,7 @@
996996
"@loader_path/Frameworks",
997997
);
998998
MACOSX_DEPLOYMENT_TARGET = 10.13;
999-
MARKETING_VERSION = 1.6.7;
999+
MARKETING_VERSION = 1.6.8;
10001000
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.macos;
10011001
PRODUCT_NAME = AttributedString;
10021002
SDKROOT = macosx;
@@ -1023,7 +1023,7 @@
10231023
"@loader_path/Frameworks",
10241024
);
10251025
MACOSX_DEPLOYMENT_TARGET = 10.13;
1026-
MARKETING_VERSION = 1.6.7;
1026+
MARKETING_VERSION = 1.6.8;
10271027
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.macos;
10281028
PRODUCT_NAME = AttributedString;
10291029
SDKROOT = macosx;
@@ -1170,7 +1170,7 @@
11701170
"@executable_path/Frameworks",
11711171
"@loader_path/Frameworks",
11721172
);
1173-
MARKETING_VERSION = 1.6.7;
1173+
MARKETING_VERSION = 1.6.8;
11741174
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.ios;
11751175
PRODUCT_NAME = AttributedString;
11761176
SKIP_INSTALL = YES;
@@ -1199,7 +1199,7 @@
11991199
"@executable_path/Frameworks",
12001200
"@loader_path/Frameworks",
12011201
);
1202-
MARKETING_VERSION = 1.6.7;
1202+
MARKETING_VERSION = 1.6.8;
12031203
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring.ios;
12041204
PRODUCT_NAME = AttributedString;
12051205
SKIP_INSTALL = YES;

Demo/Demo/Debug/DebugLabelViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class DebugLabelViewController: ViewController<DebugLabelView> {
2222
private var attributedString: AttributedString = """
2323
我的名字叫李响,我的手机号码是18611401994,我的电子邮件地址是18611401994@163.com,现在是2020/06/28 20:30。我的GitHub主页是https://github.com/lixiang1994。欢迎来Star! \("点击联系我", .action({ }))
2424
"""
25-
2625

2726
override func viewDidLoad() {
2827
super.viewDidLoad()

Sources/Extension/UIKit/UILabel/UILabelLayoutManagerDelegate.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ extension UILabelLayoutManagerDelegate {
137137
}
138138

139139
private func getMaximum(_ layoutManager: NSLayoutManager, with textStorage: NSTextStorage, for glyphRange: NSRange) -> Maximum? {
140+
// 排除换行符, 系统不用它计算行.
141+
var glyphRange = glyphRange
142+
if glyphRange.length > 1 {
143+
let property = layoutManager.propertyForGlyph(at: glyphRange.location + glyphRange.length - 1)
144+
if property == .controlCharacter {
145+
glyphRange = .init(location: glyphRange.location, length: glyphRange.length - 1)
146+
}
147+
}
148+
140149
let characterRange = layoutManager.characterRange(forGlyphRange: glyphRange, actualGlyphRange: nil)
141150

142151
var maximumLineHeightFont: UIFont?

0 commit comments

Comments
 (0)