如何更改 SwiftUI 中占位符的 fontWeight?
How can I change fontWeight of a placeholder in SwiftUI?
在我的 SwiftUI 项目中,我有一个占位符,我想将其设为 .heavy,但是当我尝试修改 fontWeight 时,它说 fontWeight 是在 Text 上定义的,我该怎么办?
这是代码:
TextField("", text: $MyModel.name[0])
.placeholder(when: MyModel.name[0].isEmpty) {
Text(player1)
.font(Font.custom("Life Savers", size: 26))
.fontWeight(.bold)
}
.font(Font.custom("Life Savers", size: 26))
//here it doesn't let me change the fontWeight to heavy
对于TextField
你使用
.font(Font.custom("Life Savers", size: 26).weight(.heavy))
在我的 SwiftUI 项目中,我有一个占位符,我想将其设为 .heavy,但是当我尝试修改 fontWeight 时,它说 fontWeight 是在 Text 上定义的,我该怎么办?
这是代码:
TextField("", text: $MyModel.name[0])
.placeholder(when: MyModel.name[0].isEmpty) {
Text(player1)
.font(Font.custom("Life Savers", size: 26))
.fontWeight(.bold)
}
.font(Font.custom("Life Savers", size: 26))
//here it doesn't let me change the fontWeight to heavy
对于TextField
你使用
.font(Font.custom("Life Savers", size: 26).weight(.heavy))