RichTextKit helps you view and edit rich text in SwiftUI
, UIKit
and AppKit
.
RichTextKit has a multi-platform SwiftUI RichTextEditor
that can be added to any app:
The RichTextEditor
supports text styles (bold, italic, underline, etc.), fonts and font sizes, colors, text alignments, image attachments, etc.
The RichTextEditor
is powered by a UIKit/AppKit RichTextView
that bridges the UIKit UITextView
and AppKit NSTextView
and adds APIs to make the view work similar on both platforms.
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: @[email protected]
- Twitter: @danielsaidi
- E-mail: [email protected]
RichTextKit is available under the MIT license. See the LICENSE file for more info.