我想将 a 的内容左对齐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))
}
}
Run Code Online (Sandbox Code Playgroud)
我得到什么:
为什么会有这样的左右填充来使文本内容居中?
感谢您的帮助
jn_*_*pdx 21
frame
您拥有的修饰符也VStack
需要对齐:
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))
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6914 次 |
最近记录: |