【发布时间】:2021-05-05 19:21:37
【问题描述】:
我正在使用属性文本属性在 UITextfield 中设置自定义占位符字体。但是我的占位符文本不是垂直居中的。Here is preview
let font = UIFont(name: Font.myFont.name, size: 15)!
let attributes = [
NSForegroundColorAttributeName: UIColor.cadetGrey,
NSFontAttributeName: font
]
exampleTextField.attributedPlaceholder = NSAttributedString(string: "Example Placeholder",
attributes: attributes)
我尝试添加
let centeredParagraphStyle = NSMutableParagraphStyle()
centeredParagraphStyle.alignment = .center
到属性仍然没有运气。我也尝试在我的 UITextBox 上使用 SizeToFit() 但一点运气都没有
【问题讨论】:
-
.alignment = .center,用于左/右/居中,水平对齐,而不是垂直对齐。检查:stackoverflow.com/questions/3665385/…contentVerticalAlignment -
你发现了吗?如果是,请发布答案。
标签: ios swift uitextfield