0

I'm trying to create a text editor similar to the one in the Notes app. The Notes app provides the following formatting options:

  • Text Styles: Title, Heading, Subheading, Body
  • Text Formatting: Bold, Italic, Underline, Strikethrough
  • Colors: Highlight, Text Color
  • Lists: Bullet, Dash, Numbered
  • Alignment: Left, Right
  • Block Quote

I want to replicate this functionality, but I'm struggling to find a way to achieve it using the standard TextEditor in SwiftUI. Is there existing support for these features in SwiftUI that I might have overlooked?

If not, would I need to build this functionality from scratch? If so, what would be the recommended approach or any resources I could use to implement it?

Here is an example of my usage of TextEditor:

import SwiftUI
import SwiftData

struct NoteView: View {
    let note: Note
    
    @Environment(\.modelContext) private var context
    
    @State var text: String = ""
    
    var body: some View {
        TextEditor(text: $text)
            .onAppear {
                text = note.body
            }
            .onChange(of: text) {
                note.body = text
            }
            .padding()
    }
}
2
  • Attributed String Commented Dec 31, 2024 at 16:17
  • I believe you have to build it yourself from the ground up using AttributedString objects as Lorem Ipsum says. (And beware, it's a fair bit of work. I've written a styled text editor before.) Commented Dec 31, 2024 at 18:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.