美文网首页
SwiftUI 之导航栏

SwiftUI 之导航栏

作者: 小凡凡520 | 来源:发表于2019-10-29 16:15 被阅读0次
struct PageView: View {
    
    var body: some View {
        NavigationView {
            VStack {
                Text("rr")
            }
            .navigationBarItems(
                leading: Button(action: {
                    print("返回")
                }, label: {
                    Text("返回")
                }),
                trailing: Button(action: {
                    print("前进")
                }, label: {
                    Text("前进")
                })
            )
            // 大标题
            .navigationBarTitle(Text("标题"))
        }
    }
}

struct PageView_Preview: PreviewProvider {
    
    static var previews: some View {
        PageView()
    }
}

回退 pop

struct ShowOrHiddenView: View {
      
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    
    var data:[Person] = [
        Person(id: 0),
        Person(id: 1),
        Person(id: 2),
        Person(id: 3),
        Person(id: 4),
        Person(id: 5),
        Person(id: 6),
    ]
    
    @State var showAll:Bool = false
    
    var body: some View {
        List {
            Toggle(isOn: $showAll, label: {
                Text(showAll ? "显示全部" : "过滤")
            })
            ForEach(data) { i in
                if self.showAll || i.id > 2 {
                    Text("\(i.id)")
                }
            }
        }
        .navigationBarItems(trailing: Button(action: {
            self.presentationMode.wrappedValue.dismiss()
        }, label: {
            Text("pop回退")
        }))
    }
}

相关文章

网友评论

      本文标题:SwiftUI 之导航栏

      本文链接:https://www.haomeiwen.com/subject/zldgvctx.html