Post

Replies

Boosts

Views

Activity

Reply to SwiftUI TextEditor doesn't work in a SwiftUI Form
Okay, so after some more research, I've gotten it as close to a natural SwiftUI element design as I can. There is still some padding that I cannot control that throws off the cursor and placeholder alignment that I'm not sure can be 'fixed'. Again, making reference to tips found on how to accomplish this on StackOverflow - https://stackoverflow.com/questions/62741851/how-to-add-placeholder-text-to-texteditor-in-swiftui. struct MyView: View { 		@State private var name: String = "" 		@State private var description: String = "" 		init() { 				/* Override TextEditor background to allow for setting a custom background in SwiftUI */ 				UITextView.appearance().backgroundColor = .clear 		} 		var body: some View { 				NavigationView { 						Form { 								Section(header: Text("Details")) { 										TextField("Name", text: self.$name) 										ZStack(alignment: .leading) { 												if self.description.isEmpty { 														VStack { 																Text("Description") 																		.padding(.top, 8) 																		.padding(.leading, 1) 																Spacer() 														} 												} 												TextEditor(text: self.$description) 														/* Set the background to that of the grouped background colour */ 														.background(Color(.secondarySystemGroupedBackground)) 														/* Allow the text overlay to be seen and emulate the necessary colour */ 														.opacity(self.description.isEmpty ? 0.7 : 1) 										} 										.frame(height: 125) 								} 						} 						.navigationBarTitle("New Goal") 				} 		} }
Jul ’20
Reply to SwiftUI TextEditor doesn't work in a SwiftUI Form
For now, I've just manually overriden the underlying UIKit element styling to allow for custom background support on the element, next to figure out how to pad the entry and set a placeholder. Original fix can be found, as everything, on StackOverflow - https://stackoverflow.com/questions/62848276/change-background-color-of-texteditor-in-swiftui. struct MyView: View { 		@State private var name: String = "" 		@State private var description: String = "" 		init() { 				/* Override TextEditor background to allow for setting a custom background in SwiftUI */ 				UITextView.appearance().backgroundColor = .clear 		} 		var body: some View { 				NavigationView { 						Form { 								Section(header: Text("Details")) { 										TextField("Name", text: self.$name) 										TextEditor(text: self.$description) 												.background(Color(.secondarySystemGroupedBackground)) 												/* Set the background to that of the grouped background colour */ 								} 						} 						.navigationBarTitle("New Thing") 				} 		} } I'm trying to emulate the multiline edit field that is present in the Reminders app, where you set a title and description. PS. Also Apple, fix your syntax highlighting in code blocks to support double forward slash...
Jul ’20