RichTextKit helps you view and edit rich text in SwiftUI
, UIKit
and AppKit
.
RichTextKit has a multi-platform SwiftUI RichTextEditor
and RichTextView
that support text styles (bold, italic, underline, etc.), fonts and font sizes, text and background colors, text alignment, image attachments etc.
RichTextKit is supported by and released with permission from Oribi and used in OribiWriter, which is available on iOS and macOS. Have a look at that app or the demo app in this repo if you want to see RichTextKit in action.
RichTextKit can be installed with the Swift Package Manager:
/~https://github.com/danielsaidi/RichTextKit.git
If you prefer to not have external dependencies, you can also just copy the source code into your app.
RichTextKit has a SwiftUI RichTextEditor
that takes a text binding and a RichTextContext
:
struct MyView: View {
@State
private var text = NSAttributedString(string: "Type here...")
@StateObject
var context = RichTextContext()
var body: some View {
RichTextEditor(text: $text, context: context) {
// You can customize the native text view here
}
}
}
The editor uses a RichTextCoordinator
to sync changes between the editor, context, and platform-specific view. You can use the context to change font, colors, alignment etc. and observe context changes to update the UI.
For more information, please see the getting started guide.
The online documentation has more information, articles, code examples, etc.
The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo
project.
You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.
Feel free to reach out if you have questions or want to contribute in any way:
- Website: danielsaidi.com
- Mastodon: @danielsaidi@mastodon.social
- Twitter: @danielsaidi
- E-mail: daniel.saidi@gmail.com
RichTextKit is available under the MIT license. See the LICENSE file for more info.