且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改 TextField 的文本大小和字段大小?

更新时间:2022-12-30 08:33:32

您可以通过更改占位符文本的字体大小来更改文本大小,这会自动调整 TextField 的高度.

You can change text size by changing the placeholder text's font size, which automatically adjusts the TextField's height.

就您而言,这看起来与您要求的非常相似:

In your case, this looks pretty similar to what you asked for:

HStack {
        Group {
            TextField($str, placeholder: Text("A"))
            TextField($str, placeholder: Text("B"))
            TextField($str, placeholder: Text("C"))
            TextField($str, placeholder: Text("D"))
        }
        .frame(width: 60, height: nil)
        .padding(.all, 5)
        .textFieldStyle(.roundedBorder)
        .font(Font.system(size: 60, design: .default))
        .multilineTextAlignment(.center)
    }