tvOS 安全文本字段,文本未垂直居中
tvOS Secure Text Field , Text is not Vertically Centered
在 apple TV 应用程序中,我想密码文本归档安全所以我检查了Secure Text Entry
属性 在属性检查器中,但 文本的文本垂直对齐方式变得不在中心 如此图像 text is not vertically centered 中,我尝试设置 contentVerticalalignment = center
但仍然无法正常工作,请提供任何帮助
也许有更好的修复方法,但我在 UITextField
子类中使用 textRect(forBounds:)
进行了破解:
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))
}
您可能需要调整翻译以适合您的字体和大小。
注意:iOS 14.
不需要这样做
也许这很明显,但我认为发生的事情是用于安全文本输入的项目符号字符不是垂直居中的 - 当项目符号略高于中心时,它们与其他文本一起看起来更好线。我认为它看起来不错,但解决它的一种方法是滚动您自己的安全文本字段,以便您可以使用不同的字符。
@Diogo T 的回答是正确的,但是我尝试更改我在文本字段中使用的字体,这也解决了我的问题:D
在 apple TV 应用程序中,我想密码文本归档安全所以我检查了Secure Text Entry
属性 在属性检查器中,但 文本的文本垂直对齐方式变得不在中心 如此图像 text is not vertically centered 中,我尝试设置 contentVerticalalignment = center
但仍然无法正常工作,请提供任何帮助
也许有更好的修复方法,但我在 UITextField
子类中使用 textRect(forBounds:)
进行了破解:
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))
}
您可能需要调整翻译以适合您的字体和大小。
注意:iOS 14.
不需要这样做也许这很明显,但我认为发生的事情是用于安全文本输入的项目符号字符不是垂直居中的 - 当项目符号略高于中心时,它们与其他文本一起看起来更好线。我认为它看起来不错,但解决它的一种方法是滚动您自己的安全文本字段,以便您可以使用不同的字符。
@Diogo T 的回答是正确的,但是我尝试更改我在文本字段中使用的字体,这也解决了我的问题:D