Swiftpack.co - danielsaidi/RichTextKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by danielsaidi.
danielsaidi/RichTextKit 0.6.1
RichTextKit is a Swift-based library for working with rich text in UIKit, AppKit and SwiftUI.
⭐️ 399
🕓 4 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/danielsaidi/RichTextKit.git", from: "0.6.1")

RichTextKit Logo

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

About RichTextKit

RichTextKit lets you edit rich text in UIKit, AppKit, and SwiftUI. It has a multi-platform RichTextView and a SwiftUI RichTextEditor that supports changing style (bold, italic, underline etc.), font, font sizes, colors, text alignment, etc. You can even drag in and paste images if you use a text format that allows it.

RichTextKit is supported by and released with permission from Oribi and used in OribiWriter, which is out on iOS and soon on 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

or with CocoaPods:

pod RichTextKit

If you prefer to not have external dependencies, you can also just copy the source code into your app.

Supported Platforms

RichTextKit supports iOS 14, macOS 11, tvOS 14 and watchOS 7.

Getting started

The online documentation has a getting started guide to help you get started with RichTextKit.

In UIKit and AppKit, you can start with creating RichTextView view instead of a UITextView or NSTextView:

RichTextView(data: myData, format: .archivedData)  // Using data
RichTextView(string: myString, format: .plainText) // Using a string

RichTextView has a lot more functionality than the native views and bridges the platform-specific api:s so that the views behave more alike across platforms. You can use this view to both view and edit rich text.

In SwiftUI, you can use a RichTextEditor, which connects a wrapped RichTextView with 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 RichTextEditor uses a coordinator to sync changes between the context and the editor. You can now use the context to change font, font size, colors, alignment etc. and observe how these properties change when you move the cursor around the text view.

For more information, please see the online documentation and getting started guide.

Documentation

The online documentation contains more information, code examples, etc., and makes it easy to overview the various parts of the library.

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

You can sponsor this project on GitHub Sponsors or get in touch for paid support.

Contact

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

License

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

GitHub

link
Stars: 399
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

4 days ago

This version is a hot fix that fixes some performance issues in 0.6.

✨ Features

  • Thanks to @jamesbradleym, RichTextKit now supports text indentation.

  • Image has new richTextIndentDecrease and richTextIndentIncrease actions.

  • NSTextAttachment has a new attachedImage property.

  • RichTextAction has new increaseIndent and decreaseIndent actions.

  • RichTextActionButtonGroup is a new view that groups multiple action buttons together.

  • RichTextAttributeWriter now supports affecting the entire text by default.

  • RichTextButtonGroup is a new view that groups multiple buttons together.

  • RichTextColorWriter now supports affecting the entire text by default.

  • RichTextContext has new canDecreaseIndent and canIncreaseIndent properties.

  • RichTextContext has new decreaseIndent() and increaseIndent() functions.

  • RichTextContext has new resetAttributedString() and setAttributedString() functions.

  • RichTextFontWriter now supports affecting the entire text by default.

  • RichTextFormatSheet now groups related buttons and also adds indent buttons.

  • RichTextIndent is a new enum for handling text indent changes.

  • RichTextIndentPicker is a new enum for picking a text indent.

  • RichTextIndentReader is a new type for managing text indents.

  • RichTextIndentWriter is a new type for managing text indents.

  • RichTextKeyboardToolbar now supports modofying the format sheet before presenting it.

  • RichTextStyleToggleGroup is a new view that groups multiple toggles together.

  • RichTextStyleWriter now supports affecting the entire text by default.

💡 Adjustments

🐛 Bug Fixes

  • This version fixes a bug where setting up an editor with a text that had image attachments, didn't resize the images until the user typed in the text editor.

💥 Breaking Changes

  • RichTextKeyboardToolbar height and spacing has been moved to RichTextKeyboardToolbarStyle.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics