I am trying to learn swiftui and faced with "markup" problem. I need to build a UI with textfield in a toolbar (like address line in Safari):
I've tried to do it like this:
import SwiftUI
struct ContentView: View {
@State var searchText: String = ""
var body: some View {
NotesListView(notesRepo: InMemoryNotesStubRepository())
.frame(minWidth: 500, minHeight: 300)
.toolbar {
ToolbarItem(placement: .primaryAction){
TextField("Search", text: $searchText)
.frame(minWidth: 300)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
And I've got something weird:
Can anyone help me how to add a textfield to a toolbar like in is in Safari (address line)?
It is possible to use style for TextField
, like
ToolbarItem(placement: .primaryAction){
TextField("Search", text: $searchText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(minWidth: 300)
}
of even custom style with with look & feel you need, see next for example https://stackoverflow.com/a/63976054/12299030
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.