Skip to content

Commit ba58df0

Browse files
author
Developer
committed
ResizeDemo 添加 GIF 图文混排效果展示
1 parent f07a5b3 commit ba58df0

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

DemoApp/ResizeDemoViewController.swift

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,33 @@ class ResizeDemoViewController: UIViewController {
143143
private func setupComplexContent() {
144144
let content = NSMutableAttributedString()
145145

146-
let title = NSAttributedString(string: "📝 BSText Demo\n\n", attributes: [
146+
let title = NSAttributedString(string: "📝 BSText Demo with GIF\n\n", attributes: [
147147
.font: UIFont.boldSystemFont(ofSize: 18),
148148
.foregroundColor: UIColor.black
149149
])
150150
content.append(title)
151151

152-
let codeBlock = """
153-
```swift
154-
let text = "Hello"
155-
print(text)
156-
```
152+
let intro = NSAttributedString(string: "BSText supports animated GIF images!\n\n", attributes: [
153+
.font: UIFont.systemFont(ofSize: 14),
154+
.foregroundColor: UIColor.darkGray
155+
])
156+
content.append(intro)
157+
158+
content.append(NSAttributedString(string: "Loading GIF from URL: ", attributes: [
159+
.font: UIFont.boldSystemFont(ofSize: 14),
160+
.foregroundColor: UIColor.black
161+
]))
162+
163+
let sampleGifUrl = URL(string: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif")!
164+
let gifAttachment = BSTextAttachment.animatedImageAttachment(
165+
url: sampleGifUrl,
166+
displaySize: CGSize(width: 120, height: 120)
167+
)
168+
content.append(NSAttributedString(attachment: gifAttachment))
157169

170+
content.append(NSAttributedString(string: "\n\n"))
171+
172+
let codeBlock = """
158173
**Bold text** and *italic text* supported.
159174
160175
> This is a blockquote with important information.
@@ -167,12 +182,18 @@ class ResizeDemoViewController: UIViewController {
167182
168183
Links: [BSText](https://github.com)
169184
170-
🎉 🚀 💡 🎯 🌟 💪 🔥 ✨ ❤️ 😊
171185
"""
172186

173187
let parser = BSTextMarkdownParser()
174188
content.append(parser.parse(codeBlock))
175189

190+
content.append(NSAttributedString(string: "\nEmojis: "))
191+
let emojis = ["🎉", "🚀", "💡", "🎯", "🌟"]
192+
for emoji in emojis {
193+
let emojiAttachment = BSTextAttachment.emojiAttachment(emoji: emoji)
194+
content.append(NSAttributedString(attachment: emojiAttachment))
195+
}
196+
176197
textView.attributedText = content
177198
}
178199

0 commit comments

Comments
 (0)