我想将 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)
我得到什么:
为什么会有这样的左右填充来使文本内容居中?
感谢您的帮助
我想创建一个十进制格式化程序,最多可显示 2 位十进制数字,并带有给定的分隔符。
例如使用分隔符","
input -> output
3.0 -> "3"
3.1 -> "3,1"
3.14 -> "3,14"
3.141 -> "3,14"
3.149 -> "3,15"
Run Code Online (Sandbox Code Playgroud)
我想在 Kotlin 中执行此操作,我想我必须使用DecimalFormat但不明白该怎么做。请你帮助我好吗?