-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
220afc9
commit 4677599
Showing
5 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
BilibiliLive/Component/Video/Replys+AttritubedString.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Replys+AttritubedString.swift | ||
// BilibiliLive | ||
// | ||
// Created by yicheng on 9/11/2024. | ||
// | ||
|
||
import Kingfisher | ||
import UIKit | ||
|
||
extension Replys.Reply { | ||
func createAttributedString(displayView: UIView) -> NSAttributedString? { | ||
guard let emote = content.emote, !emote.isEmpty else { | ||
return nil | ||
} | ||
let attr = NSMutableAttributedString(string: content.message) | ||
for (tag, emote) in emote { | ||
guard let url = URL(string: emote.url) else { continue } | ||
let ranges = attr.string.ranges(of: tag).reversed() | ||
for range in ranges { | ||
let textAttachment = NSTextAttachment() | ||
attr.replaceCharacters(in: NSRange(range, in: attr.string), with: NSAttributedString(attachment: textAttachment)) | ||
// TODO: 文本对其,添加间距 | ||
KF.url(url) | ||
.resizing(referenceSize: CGSize(width: 36, height: 36)) | ||
.roundCorner(radius: .point(15)) | ||
.set(to: textAttachment, attributedView: displayView) | ||
} | ||
} | ||
return attr | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters