admin管理员组文章数量:1129451
I want to descrease row height of list with the following code:
List(elements, id: \.id, children: \.children, selection: $selected) { element in
HStack {
Image(systemName: element.children != nil ? "folder" : "list.bullet.rectangle.portrait")
Text(element.name)
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowSeparator(.hidden, edges: .all)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
.environment(\.defaultMinListRowHeight, 20)
.listStyle(.inset)
The UI looks like:
But I want the background to be blur. After I change .listStyle(.inset)
to .listStyle(.sidebar)
, the row height is increased.
No matter how I lower the paddings or insets of list elements, the row height is not decreased. I found that XCode has did it.
But I cannot find a way to make it.
Environment:
- macOS 15.2
- XCode 16.2
I want to descrease row height of list with the following code:
List(elements, id: \.id, children: \.children, selection: $selected) { element in
HStack {
Image(systemName: element.children != nil ? "folder" : "list.bullet.rectangle.portrait")
Text(element.name)
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowSeparator(.hidden, edges: .all)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
.environment(\.defaultMinListRowHeight, 20)
.listStyle(.inset)
The UI looks like:
But I want the background to be blur. After I change .listStyle(.inset)
to .listStyle(.sidebar)
, the row height is increased.
No matter how I lower the paddings or insets of list elements, the row height is not decreased. I found that XCode has did it.
But I cannot find a way to make it.
Environment:
- macOS 15.2
- XCode 16.2
1 Answer
Reset to default 0Some parts of SwiftUI list styles just cannot be customised. I'd suggest keep using the .inset
style, and add a NSVisualEffectView
as the background manually.
struct BackgroundBlur : NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
let view = NSVisualEffectView()
view.state = .active
return view
}
func updateNSView(_ view: NSVisualEffectView, context: Context) { }
}
.listStyle(.inset)
.scrollContentBackground(.hidden) // remember to hide the default background or else our own background will not be visible
.background {
BackgroundBlur().ignoresSafeArea()
}
本文标签: How to decrease row height of list in sidebar style on swiftui under macosStack Overflow
版权声明:本文标题:How to decrease row height of list in sidebar style on swiftui under macos? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736744766a1950711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论