我正在为tvOS构建一个SwiftUI应用程序,当前正在尝试实现UI。我在底部具有NavigationView,在顶部具有标签,并且我希望标签显示当前聚焦的NavigationLink。这是我的代码:
@State private var selection: String? = nil
。
ZStack {
Color.red.edgesIgnoringSafeArea(.all)
VStack {
Text(selection ?? "no value").background(Color.green)
NavigationView {
ScrollView(.horizontal) {
HStack{
VStack {
NavigationLink(destination: view2, tag: "1", selection: $selection) {
Image("placeholder")
.scaledToFit().frame(width:400, height: 225) }
Text("Button")
}
VStack {
NavigationLink(destination: view2, tag: "2", selection: $selection) {
Image("placeholder")
.scaledToFit().frame(width:400, height: 225) }
Text("Button")
}
...
}
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .bottomLeading)
}
}
}
}
但是,当我更改选择内容并且标签不显示任何值时,标签值不会更改:
任何想法我应该在那做什么?
答案 0 :(得分:0)
我相信您的Image
是您NavigationLink
的选择效果,一个简单的解决方法是在图像中添加.padding()
。 Here是一些很好的示例,可用于自定义NavigationLink
选择。更具体地说,{{1}中的.buttonStyle
。
NavigationLink