简体   繁体   English

防止SwiftUI系统映像动态更改导航栏项目的大小

[英]Prevent SwiftUI System Image from dynamically changing size for navigation bar item

I would like to add a plus button to the navigation bar items using the system plus image in SwiftUI. 我想在SwiftUI中使用系统加号图像向导航栏项添加加号按钮。 However, I am unable to prevent the system image from scaling dynamically when the accessibility font changes. 但是,当辅助功能字体更改时,我无法阻止系统映像动态缩放。

How can I stop it resizing so it acts like a standard UINavigationBarButtonItem system plus button? 如何停止调整大小,使其像标准的UINavigationBarButtonItem系统加按钮一样工作?

The accessibility feature of holding on to a navigation bar button for large font types also doesn't work like it does with UIKit. 按住导航栏按钮以处理大字体类型的可访问性功能也无法像使用UIKit那样起作用。

Really frustrating that a potentially simple thing can't be done with SwiftUI and that accessibility hasn't been thought about. 令人非常沮丧的是,使用SwiftUI无法完成可能很简单的事情,并且尚未考虑可访问性。 The SwiftUI tutorials profile bar button also doesn't work for large font sizes. SwiftUI教程配置文件栏按钮也不适用于大字体。 (PS SwiftUI is the future) (PS SwiftUI是未来)

Here was my attempt: 这是我的尝试:

struct ContentView : View {
    var body: some View {
        NavigationView {
            List {
                Text("Stop + Bar Button resizing")
                    .lineLimit(nil)
            }
            .navigationBarTitle(Text("Plus"))
            .navigationBarItems(trailing:
                PlusNavigationButton()
            )
        }
    }
}

struct PlusNavigationButton: View {
    var body: some View {
        PresentationButton(
            Image(systemName: "plus")
                .resizable()
                .frame(width: 44, height: 44),
            destination: NewView())
    }
}

加栏按钮图像动态调整大小

You should build what you exactly want. 您应该构建自己真正想要的东西。 So if you want to use 16x16 image with some extra hitTest area, you can build like this: 因此,如果要在额外的hitTest区域中使用16x16图像,则可以这样构建:

var body: some View {
    PresentationButton(
        HStack() {
           Spacer()
           Image(systemName: "plus")
               .resizable()
               .frame(width: 16, height: 16)
           Spacer()
        }.frame(width: 44, height: 44),    
        destination: NewView()
    )
}

or if you like some space around your image and let it fill the rest, you can: 或者,如果您喜欢图像周围的一些空间并让其填充其余部分,则可以:

var body: some View {
    PresentationButton(
        Image(systemName: "plus")
            .resizable()
            .padding(14)
            .frame(width: 44, height: 44),  
        destination: NewView()
    )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM