美文网首页SwiftUI实战
SwiftUI实战-系统NavigationView自定义tit

SwiftUI实战-系统NavigationView自定义tit

作者: ISwiftUI | 来源:发表于2022-05-06 07:08 被阅读0次

    系统NavigationView自定义titleView

    效果图:


    自定义titleView.gif

    相关源码:
    ContentView.swift

    
    import SwiftUI
    
    struct ContentView: View {
    
        var body: some View {
            NavigationView {
                VStack(spacing: 20) {
                    NavigationLink(destination: Page2()) {
                        Text("Page 2")
                    }
                    NavigationLink(destination: Search()) {
                        Text("Search")
                    }
                }
                .navigationBarTitleView(displayMode: .inline) { Text("Page 1").foregroundColor(.orange) }
            }
        }
    }
    
    struct Page2: View {
    
        var body: some View {
            Text("Page 2")
                .navigationBarTitleView(displayMode: .inline) { Text("Page 2").foregroundColor(.blue) }
        }
    }
    
    struct Search: View {
    
        @State var term = ""
    
        var body: some View {
            Text("Page 2")
                .navigationBarTitleView(displayMode: .inline) { TextField("Search", text: $term) }
        }
    }
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
    

    NavigationTitleView.swift

    相关文章

      网友评论

        本文标题:SwiftUI实战-系统NavigationView自定义tit

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