admin管理员组文章数量:1200781
I have a View
in a NavigationSplitView
with a .toolbar
. When placed in a horizontally compact configuration (e.g phone, slide-over or split) the native behaviour is to collapse extra buttons into a context menu.
When touched, the context menu will not display the collapsed items.
How do I get the context menu to display the extra toolbar items.
import SwiftUI
struct ContentView: View {
@State var selection: Int? = nil
//sugar
func label() -> Image {
Image(systemName: "eye")
}
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(0..<10) { item in
Text("hey \(item)").id(item)
}
}
} detail: {
VStack {
Text("Hello, world!")
}
.padding()
.navigationTitle("Woo")
.toolbar {
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
}
}
}
}
I have a View
in a NavigationSplitView
with a .toolbar
. When placed in a horizontally compact configuration (e.g phone, slide-over or split) the native behaviour is to collapse extra buttons into a context menu.
When touched, the context menu will not display the collapsed items.
How do I get the context menu to display the extra toolbar items.
import SwiftUI
struct ContentView: View {
@State var selection: Int? = nil
//sugar
func label() -> Image {
Image(systemName: "eye")
}
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(0..<10) { item in
Text("hey \(item)").id(item)
}
}
} detail: {
VStack {
Text("Hello, world!")
}
.padding()
.navigationTitle("Woo")
.toolbar {
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
ToolbarItem{ Button(action: { }, label: { label() }) }
}
}
}
}
Share
Improve this question
edited Jan 22 at 12:49
jonrsharpe
122k30 gold badges266 silver badges473 bronze badges
asked Jan 22 at 12:49
Warren BurtonWarren Burton
17.4k3 gold badges54 silver badges76 bronze badges
1 Answer
Reset to default 0Although it's legal and valid SwiftUI to place a Button
with a Image
label into a toolbar:
ToolbarItem{ Button(action: { }, label: { Image(systemName: "eye") }) }
To work with all trait configurations the label needs to be a Label
ToolbarItem{ Button(action: { }, label: { Label("yo", systemImage: "eye") }) }
yielding the desired context menu.
struct ContentView: View {
@State var selection: Int? = nil
//sugar
func label(_ msg: Int) -> Label<Text, Image> {
Label("yo \(msg)", systemImage: "eye")
}
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(0..<10) { item in
Text("hey \(item)").id(item)
}
}
} detail: {
VStack {
Text("Hello, world!")
}
.padding()
.navigationTitle("Woo")
.toolbar {
ToolbarItem{ Button(action: { }, label: { label(1) }) }
ToolbarItem{ Button(action: { }, label: { label(2) }) }
ToolbarItem{ Button(action: { }, label: { label(3) }) }
ToolbarItem{ Button(action: { }, label: { label(4) }) }
ToolbarItem{ Button(action: { }, label: { label(5) }) }
ToolbarItem{ Button(action: { }, label: { label(6) }) }
}
}
}
}
本文标签: swiftuiToolbar in Horizontal Compact mode doesn39t display overflowed itemsStack Overflow
版权声明:本文标题:swiftui - Toolbar in Horizontal Compact mode doesn't display overflowed items - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738563352a2099665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论