So I'm relatively new to SwiftUI, and I'm trying to add a UISearchBar into my navigation bar, but I'm having trouble getting it to show up. If I add it as a separate component, it appears but it's too far down the screen. Here's what I have so far:
UISearchBar Component:
struct SearchBar2: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> UISearchBar {
let searchbar = UISearchBar(frame: .zero)
return searchbar
}
func updateUIView(_ uiView: UISearchBar, context: Context) {
uiView.text = text
}
}
UIView:
var body: some View{
ZStack{
NavigationView{
VStack {
NavigationLink()
{
InitView()
}.buttonStyle(PlainButtonStyle())
ZStack {
HStack {
//some items here
}
}.toolbar{
SearchBar2(text: $text)
}
DayView()
}
}
}
}
And here's what this looks like on the simulator: Screenshot