HStack があります:
struct BottomList: View {
var body: some View {
HStack() {
ForEach(navData) { item in
NavItem(image: item.icon, title: item.title)
}
}
}
}
* コンテンツが均等間隔で中央に配置され、幅全体が自動的に埋められるにはどうすればよいでしょうか?
ちなみにBootstrapのCSSクラスと同じです.justify-content-around
ベストアンサー1
レイアウトframe
修飾子と.infinity
パラメータをmaxWidth
使用すると、追加のビューを必要とせずにこれを実現できますShape
。
struct ContentView: View {
var data = ["View", "V", "View Long"]
var body: some View {
VStack {
// This will be as small as possible to fit the data
HStack {
ForEach(data, id: \.self) { item in
Text(item)
.border(Color.red)
}
}
// The frame modifier allows the view to expand horizontally
HStack {
ForEach(data, id: \.self) { item in
Text(item)
.frame(maxWidth: .infinity)
.border(Color.red)
}
}
}
}
}