Reputation: 251
I'm new to SwiftUI and was wondering how to center the content (horizontally and vertically) inside my table view cells. My current code is as follows:
var body: some View {
List(list) { item in
VStack(alignment: .center) {
Image(systemName: item.imageName)
Text(item.text)
}
}
}
My goal is to align the VStack in the center of the cell. Thanks!
Upvotes: 2
Views: 872
Reputation: 257543
Here is possible approach (alignment: .center
is by default, so can be dropped)
List(list) { item in
HStack {
Spacer()
VStack {
Image(systemName: item.imageName)
Text(item.text)
}
Spacer()
}
}
Upvotes: 2