我想将搜索栏停留在导航栏上
我的屏幕如下所示:
我想像这样删除搜索栏和导航栏之间的空间:
这是我的代码:
struct TimelineView : View {
@State private var searchQuery: String = ""
var timeline: [Timeline] = []
var body: some View {
NavigationView {
VStack {
SearchBar(text: self.$searchQuery)
HStack(alignment: .center) {
Spacer()
.frame(width: 30)
Image("CameraIcon")
.resizable()
.frame(width: 50.0 , height: 50.0)
Spacer()
.frame(width: 30)
Text("Whats in your mind ?")
Spacer()
.frame(height: 90.0)
}
List(timeline) { item in
TimelineCell(timeline: item)
}
}
}
}
}
struct TimelineCell : View {
let timeline: Timeline
var body: some View {
return NavigationLink(destination: RegistrationView()) {
VStack(alignment: .leading) {
Text(timeline.name)
Text(timeline.like)
.font(.subheadline)
.color(.gray)
}
}
}
}
#if DEBUG
struct TimelineView_Previews : PreviewProvider {
static var previews: some View {
TimelineView(timeline: testData)
}
}
#endif
在我的代码中,搜索栏是由UIViewRepresentable创建的自定义UI。