更改Swiftui的导航栏的大小

发布于 2025-01-24 16:50:18 字数 8 浏览 4 评论 0原文

您好,社区

Hello SO community ????????

I'm trying to recreate NavigationBar from Contact tab Apple's Phone in my SwiftUI app.
enter image description here

I played around with .toolbar and modifications but really can't recreate it. I wanna replace TextField to SegmentPicker with saving all behavior of .navigationBarTitleDisplayMode(.inline). But don't know is it possible to use SwiftUI only to get it or need to dive into UIKit. I'm not the expert of UIKit and I will be glad for any help. I want use this NavBar in a exact screen in the app and if possible do not change my preferences of NavBar on other part of app. My code:

import SwiftUI

struct NavBar: View {

@State var pickerOptions: Int = 0

var body: some View {
    NavigationView {
        ScrollView(.vertical) {
            VStack {
                Text("Hello, World!")
            }
        }
        .navigationBarTitleDisplayMode(.inline)
        .toolbar {
            ToolbarItem(placement: .principal) {
                SegmentPicker
            }
            ToolbarItem(placement: .navigationBarTrailing) {
                Image(systemName: "plus")
            }
            ToolbarItem(placement: .navigationBarLeading) {
                Text("Groups")
            }
        }
    }
}

private var SegmentPicker: some View {
    VStack {
        Text("Contacts").font(.body.weight(.semibold))
        Picker("Options", selection: $pickerOptions) {
            Text("Cons").tag(0)
            Text("Prons").tag(1)
        }
        .pickerStyle(.segmented)
        .frame(width: 200)
    }
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文