在apple TV应用程序中,我想使 密码文本存档安全 所以我检查了 Secure Text Entry
属性,但在属性检查器中的 文本的垂直排列变得不在中心了。 如图 文字不垂直居中 我试着设置了 contentVerticalalignment = center
但仍然无法工作,任何帮助,请
也许有一个更好的方法来解决,但我黑客与 textRect(forBounds:)
在...中 UITextField
子类。
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
guard isSecureTextEntry else {
return super.placeholderRect(forBounds: bounds)
}
return super.textRect(forBounds: bounds)
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
guard isSecureTextEntry else {
return super.textRect(forBounds: bounds)
}
return bounds.applying(.init(translationX: 0, y: 10))
}
你可能需要调整翻译以适应你的字体和大小。
也许这是显而易见的,但我认为那里发生的事情是用于安全文本输入的子弹字符没有垂直居中--当子弹字符高于中心线一点时,它们与其他文本一起看起来会更好。我认为它看起来很好,但有一个方法可以解决这个问题,那就是滚动你自己的安全文本字段,这样你就可以使用不同的字符。
@Diogo T的回答是正确的 ,不过我试着改变了我正在使用的文本字段的字体,这也为我解决了这个问题:D。