我想在SwiftUI中使用系统加号图像向导航栏项添加加号按钮。但是,当辅助功能字体更改时,我无法阻止系统图像动态缩放。
如何停止调整大小,使其像标准的UINavigationBarButtonItem系统加按钮?
按住导航栏按钮以获取大字体类型的可访问性功能也无法像使用UIKit那样起作用。
真正令人沮丧的是,使用SwiftUI无法完成可能很简单的事情,并且尚未考虑可访问性。SwiftUI教程配置文件栏按钮对于大字体也不起作用。(PS SwiftUI是未来)
这是我的尝试:
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())
}
}
您应该构建自己真正想要的东西。因此,如果您想在额外的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()
)
}
或者,如果您希望图像周围有一些空间并让其填充其余部分,则可以:
var body: some View {
PresentationButton(
Image(systemName: "plus")
.resizable()
.padding(14)
.frame(width: 44, height: 44),
destination: NewView()
)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句