Skip to content

RichTextKit is a Swift-based library for working with rich text in UIKit, AppKit and SwiftUI.

License

Notifications You must be signed in to change notification settings

r-jarvis/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 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.

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.

About

RichTextKit is a Swift-based library for working with rich text in UIKit, AppKit and SwiftUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 99.3%
  • Other 0.7%