I am using a TextEditor and do not want the text to be directly touching the left side. I want it to look like most notes or document apps where the text is not crunched up on the top or sides.
I tried to use a padding (as seen in the photo), but it shifted the actual TextEditor itself and not the text inside the editor. How can I pad the text but not the editor?
ZStack (alignment: .leading){
if test.isEmpty{
VStack{
Text("Write something....")
.padding(.top)
.padding(.leading, 20)
.opacity(0.6)
.font(.system(size: 20))
.foregroundColor(.black)
Spacer()
}
} else{
VStack{
Text("")
}
}
VStack{
TextEditor(text: $note.text)
.padding()
.opacity(note.text.isEmpty ? 0.85 : 1)
.font(.custom("SanFrancisco", fixedSize: 20))
.onReceive(note.publisher(for: \.text), perform: setName)
.onReceive(
note.publisher(for: \.text)
.debounce(for: 0.5, scheduler: RunLoop.main)
.removeDuplicates()
){ _ in
try? PersistenceController.shared.saveContext()
}
.navigationTitle(note.name)
}
}
}
Can you try this (iOS 16+)
ZStack {
TextEditor(text: $text)
.padding()
}
.scrollContentBackground(.hidden)
.background(Color.gray.opacity(0.1))
.cornerRadius(15)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With