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.
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.
RichTextKit supports iOS 14
, macOS 11
, tvOS 14
and watchOS 7
.
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.
The online documentation contains more information, code examples, etc., and makes it easy to overview the various parts of the library.
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 this project on GitHub Sponsors or get in touch for paid support.
Feel free to reach out if you have questions or if you want to contribute in any way:
RichTextKit is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 399 |
Last commit: 4 days ago |
This version is a hot fix that fixes some performance issues in 0.6.
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.
RichTextKeyboardToolbar
height
and spacing
has been moved to RichTextKeyboardToolbarStyle
.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics