如何在SwiftUI TextField中将占位符文本居中?
我的代码如下:
TextField("Enter Your Email", text: self.$username)
如何使占位符“输入您的电子邮件”在文本字段中居中?
答案 0 :(得分:5)
TextField("Enter Your Email", text: self.$username)
.multilineTextAlignment(TextAlignment.center)
答案 1 :(得分:1)
您可以使用以下代码:
yourtextfield.textAlignment = .center
答案 2 :(得分:0)
let centeredParagraphStyle = NSMutableParagraphStyle()
centeredParagraphStyle.alignment = .center
let attributedPlaceholder = NSAttributedString(string: "Placeholder", attributes: [NSAttributedString.Key.paragraphStyle: centeredParagraphStyle])
textField.attributedPlaceholder = attributedPlaceholder
答案 3 :(得分:0)
TextField("Enter Your Email", text: self.$username)
.multilineTextAlignment(.trailing) // .center|| .leading