VStack 内容居中而不是左对齐
VStack content is centered instead of aligned left
我想左对齐 VStack
的内容而不是居中,但我不知道该怎么做。这是我的代码:
struct SortRow: View {
var sortType: SortType
@AppStorage(sortKey) var currentSorting: SortType = .winOrLoss
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(sortType.name)
.multilineTextAlignment(.leading)
.font(.system(size: 15.0))
.foregroundColor(Color(sortType == currentSorting ? UIColor.white : UIColor.systemGray2))
Text(sortType.detail)
.multilineTextAlignment(.leading)
.font(.system(size: 13.0))
.foregroundColor(Color(sortType == currentSorting ? UIColor.white : UIColor.systemGray))
}
.frame(maxWidth: .infinity)
.padding(12)
.background(Color(sortType == currentSorting ? UIColor.systemGreen : UIColor.systemBackground))
}
}
我得到的:
为什么文本内容居中会有左右填充?
感谢您的帮助
您在 VStack
上的 frame
修饰符也需要对齐:
struct SortRow: View {
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text("Win or loss")
.multilineTextAlignment(.leading)
.font(.system(size: 15.0))
.foregroundColor(.white)
Text("Sort by how much money has been won or lost")
.multilineTextAlignment(.leading)
.font(.system(size: 13.0))
.foregroundColor(.white)
}
.frame(maxWidth: .infinity, alignment: .leading) //<-- Here
.padding(12)
.background(Color(uiColor: UIColor.systemGreen))
}
}
我想左对齐 VStack
的内容而不是居中,但我不知道该怎么做。这是我的代码:
struct SortRow: View {
var sortType: SortType
@AppStorage(sortKey) var currentSorting: SortType = .winOrLoss
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(sortType.name)
.multilineTextAlignment(.leading)
.font(.system(size: 15.0))
.foregroundColor(Color(sortType == currentSorting ? UIColor.white : UIColor.systemGray2))
Text(sortType.detail)
.multilineTextAlignment(.leading)
.font(.system(size: 13.0))
.foregroundColor(Color(sortType == currentSorting ? UIColor.white : UIColor.systemGray))
}
.frame(maxWidth: .infinity)
.padding(12)
.background(Color(sortType == currentSorting ? UIColor.systemGreen : UIColor.systemBackground))
}
}
我得到的:
为什么文本内容居中会有左右填充?
感谢您的帮助
您在 VStack
上的 frame
修饰符也需要对齐:
struct SortRow: View {
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text("Win or loss")
.multilineTextAlignment(.leading)
.font(.system(size: 15.0))
.foregroundColor(.white)
Text("Sort by how much money has been won or lost")
.multilineTextAlignment(.leading)
.font(.system(size: 13.0))
.foregroundColor(.white)
}
.frame(maxWidth: .infinity, alignment: .leading) //<-- Here
.padding(12)
.background(Color(uiColor: UIColor.systemGreen))
}
}