小编Kel*_*ton的帖子

VStack内容居中而不是左对齐

我想将 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)

我得到什么:

在此输入图像描述

为什么会有这样的左右填充来使文本内容居中?

感谢您的帮助

swiftui vstack

8
推荐指数
1
解决办法
6914
查看次数

如何创建 Kotlin 十进制格式化程序

我想创建一个十进制格式化程序,最多可显示 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但不明白该怎么做。请你帮助我好吗?

numberformatter decimalformat kotlin

0
推荐指数
1
解决办法
1422
查看次数

标签 统计

decimalformat ×1

kotlin ×1

numberformatter ×1

swiftui ×1

vstack ×1