如何在SwiftUI中粘贴搜索栏并删除导航栏和搜索栏之间的空间

时间:2019-07-23 10:24:49

标签: ios swift swiftui xcode11

我想将搜索栏停留在导航栏上

我的屏幕如下所示: Original Output

我想像这样删除搜索栏和导航栏之间的空间: Desired Output

这是我的代码:

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。

0 个答案:

没有答案