swift - 如何在swiftui中自定义导航栏

标签 swift uikit swiftui

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

最佳答案

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

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

关于swift - 如何在swiftui中自定义导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57736886/

相关文章:

swift - Swift 创建 Outlet 时 UISwitch 无法正确执行

ios - iPhone模拟器播放视频,真实设备不会

ios - 如何一次只允许一个UIImageView被触摸

ios - 将文字写入透明的UIImage

arrays - 如何初始化@Binding SwiftUi

ios - Xcode 11 Beta 5 - 模态仅触发一次

swiftui - 隐藏 `TabView` 的导航栏不起作用

swift - 有没有办法在 VStack 中放置两个图像并调整图像大小和缩放到填充? swift 用户界面

ios - 升级到 MonoTouch 6 后自动旋转停止工作

swift - 无法在父级的 .xib 文件中设置标签文本 - Swift