如何在swiftui中自定义导航栏

时间:2019-08-31 09:43:27

标签: swift uikit swiftui

如何在 swiftui 中实现此导航栏。它看起来像默认的.largeTitle,但是高度和右键不同 Navigation as needed

1 个答案:

答案 0 :(得分:1)

这是我能想到的最好的解决方案。您基本上将导航栏生成的标题设置为空字符串,并在导航栏的前视图中构造自己的标题视图。

import SwiftUI

struct NavigationBarView: View {
    var body: some View {
        NavigationView {
            Text("NavigationBarView")
                .navigationBarTitle("") //Set title to none so that it won't put the bottom title
                .navigationBarItems(leading:
                    //This is your made up title, put in the leading view so it is up top aligned with the plus button
                    Text("Navigation Bar").font(.largeTitle).bold()
                    //This is the plus button, on the right side, aka trailing view
                    , trailing: Button(action: {

                    }, label: {
                            Image(systemName: "plus.circle")
                    })
            )

        }
    }
}

enter image description here