NuPlay/RichText
关于
Easily show RichText(html) in SwiftUI
网站与应用开发可以做什么
- Cross-platform — iOS 15.0+ and macOS 12.0+, Swift 5.9+
- Automatic sizing — the view resizes itself as the content lays out, including late images, web fonts and <details> toggles
- Theming — automatic light/dark mode, custom color sets, transparent or custom backgrounds
- Typography — system, monospaced, italic, custom and bundled fonts, with Dynamic Type support
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文RichText
Render HTML in SwiftUI.
RichText sizes itself to its content, so HTML fits into a layout like any other view.
Styling, light and dark theming, custom fonts, media callbacks and typed errors are built in.

|
|
|
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------: |:------------------------------------------------------------------------------------------------------------------------------: |
| Light Mode | Dark Mode |
✨ Features
- Cross-platform — iOS 15.0+ and macOS 12.0+, Swift 5.9+
- Automatic sizing — the view resizes itself as the content lays out, including late images, web fonts and
<details>toggles - Theming — automatic light/dark mode, custom color sets, transparent or custom backgrounds
- Typography — system, monospaced, italic, custom and bundled fonts, with Dynamic Type support
- Interactive media — click callbacks for images and videos
- Link handling — Safari,
SFSafariViewController, or your own handler - HTML5 —
<figure>,<details>,<summary>,<figcaption>and the semantic elements - Error reporting — typed errors for load, configuration and CSS failures
tvOS and watchOS are not supported: Apple does not ship
WKWebViewon those platforms.
🚀 Quick Start
import SwiftUI
import RichText
struct ContentView: View {
let html = """
<h1>Welcome to RichText</h1>
<p>A powerful HTML renderer for SwiftUI.</p>
"""
var body: some View {
ScrollView {
RichText(html: html)
.colorScheme(.auto)
.lineHeight(170)
.imageRadius(12)
.placeholder { ProgressView() }
.onMediaClick { media in
if case .image(let src) = media { print(src) }
}
.onError { error in print(error) }
}
}
}
See the API reference for every modifier, and advanced usage for custom fonts, themes and complete examples.
📦 Installation
Swift Package Manager (Recommended)
- In Xcode, select File → Add Package Dependencies...
- Enter the repository URL:
https://github.com/NuPlay/RichText.git - Select version rule: "Up to Next Major Version" from "3.1.1"
- Click Add Package
Manual Package.swift
Add RichText to your Package.swift:
dependencies: [
.package(url: "https://github.com/NuPlay/RichText.git", .upToNextMajor(from: "3.1.1"))
],
targets: [
.target(
name: "YourTarget",
dependencies: ["RichText"]
)
]
📖 Documentation
| Document | Contents |
|---|---|
| API Reference | Every initializer, modifier and utility |
| Advanced Usage | Custom fonts, theming, media handling, performance, full examples |
| Troubleshooting | Common issues and platform-specific notes |
| Migration Guide | Upgrading from v2.x |
| Changelog | Release notes |
| Contributing | How to report issues and send patches |
🌟 Used By
Open-source apps that render their content with RichText:
| Project | What it is |
|---|---|
| IBM/mac-ibm-notifications | macOS agent for displaying notifications and alerts to managed devices |
| AudioBooth | iOS companion app for Audiobookshelf |
Each of these declares RichText in its public dependency manifest. No affiliation or endorsement is implied in either direction. Using RichText in your project? Open a PR to add it.
📄 License
RichText is available under the MIT license. See the LICENSE file for more info.
🙏 Acknowledgments
- Built with WebKit for reliable HTML rendering
- Inspired by the SwiftUI community's need for rich text solutions
- Thanks to all contributors and users
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for the SwiftUI community
探索相关项目
加载中…