Skip to content

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.

License

Notifications You must be signed in to change notification settings

danielsaidi/RichTextKit

Repository files navigation

RichTextKit Logo

Version Swift 5.8 MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About RichTextKit

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.

Installation

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.

Getting started

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.

Documentation

The online documentation has more information, articles, code examples, etc.

Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo project.

Support my work

You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.

Contact

Feel free to reach out if you have questions or want to contribute in any way:

License

RichTextKit is available under the MIT license. See the LICENSE file for more info.