Android技术交流ios技术交流

SwiftUI篇-5 专题NavigationView、Navi

2021-02-28  本文已影响0人  浪人残风

NavigationView:标题、展示模式、隐藏导航栏、隐藏返回按钮、添加导航栏按钮

NavigationLink:Text文本跳转、Image图片跳转、Button按钮跳转、点击按钮根据业务跳转到不同页面

NavigationView 标题、展示模式

import SwiftUI

struct LargeNavView: View {
    var displayMode: NavigationBarItem.TitleDisplayMode
    var title: String
    var body: some View {
        Text("Hello, World!").navigationBarTitle("large标题", displayMode: displayMode)
    }
}

struct LargeNavView_Previews: PreviewProvider {
    static var previews: some View {
        LargeNavView(displayMode: .automatic, title: "large标题")
    }
}

NavigationBarItem.TitleDisplayMode共有三个选项:

NavigationView 添加导航栏按钮

                NavigationLink(
                    destination:   Text("large标题").navigationBarItems(trailing: HStack{
                        Button("trailing btn1") {
                              print("trailing btn1")
                        }
                        Button("trailing btn2") {
                              print("trailing btn2")
                        }
                    })
                    .navigationTitle("标题")
                    ,
                 label: {
                    Text("导航栏按钮")
                 })

NavigationView 隐藏导航栏

NavigationLink(destination: Text("NavigationLinkpage").navigationBarHidden(true)) {
  Text("隐藏导航栏")
}

NavigationView 隐藏返回按钮

NavigationLink(destination: Text("NavigationLinkpage").navigationBarBackButtonHidden(true).navigationTitle("title")) {
  Text("隐藏返回按钮")
}

NavigationView Text文本跳转

 NavigationLink(destination: Text("NavigationLink page")) {
                        Text("text NavigationLink")
 }

NavigationView Image图片跳转

NavigationLink(destination: Text("NavigationLink page")) {
                    Image("chincoteague").frame(width: 100, height: 100).clipped()
}

NavigationView 点击Button按钮跳转

 @State private var showButtonView = false
 
NavigationLink(destination: Text("NavigationLink page"), isActive: $showButtonView) { EmptyView() }
                Button("点击按钮跳转页面") {
                    self.showButtonView = true
}

NavigationView 点击按钮根据业务跳转到不同页面

上一篇下一篇

猜你喜欢

热点阅读