Skip to content

Commit 4939a80

Browse files
committed
feat: 评论表情对齐
1 parent 4677599 commit 4939a80

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

BilibiliLive/Component/Video/Replys+AttritubedString.swift

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@ extension Replys.Reply {
1717
for (tag, emote) in emote {
1818
guard let url = URL(string: emote.url) else { continue }
1919
let ranges = attr.string.ranges(of: tag).reversed()
20+
let descender: CGFloat
21+
if let label = displayView as? UILabel {
22+
descender = label.font.descender
23+
} else {
24+
descender = -5
25+
}
26+
let emoteSize = 36.0
2027
for range in ranges {
2128
let textAttachment = NSTextAttachment()
22-
attr.replaceCharacters(in: NSRange(range, in: attr.string), with: NSAttributedString(attachment: textAttachment))
23-
// TODO: 文本对其,添加间距
29+
let textAttachmentString = NSMutableAttributedString(attachment: textAttachment)
30+
textAttachmentString.append(NSAttributedString(string: " ", attributes: [.font: UIFont.systemFont(ofSize: 10)]))
31+
attr.replaceCharacters(in: NSRange(range, in: attr.string), with: textAttachmentString)
2432
KF.url(url)
25-
.resizing(referenceSize: CGSize(width: 36, height: 36))
26-
.roundCorner(radius: .point(15))
33+
.resizing(referenceSize: CGSize(width: emoteSize, height: emoteSize))
34+
.onSuccess { [weak textAttachment] res in
35+
guard let textAttachment = textAttachment else { return }
36+
textAttachment.bounds = CGRect(x: 0, y: descender, width: emoteSize, height: emoteSize)
37+
}
2738
.set(to: textAttachment, attributedView: displayView)
2839
}
2940
}

0 commit comments

Comments
 (0)