Reputation: 3
I'm trying to create a text editor similar to the one in the Notes app. The Notes app provides the following formatting options:
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()
}
}
Upvotes: 0
Views: 66