我想要一个文本字段来填写用户名并且调整大小有效,但字体大小不会随之改变。我怎样才能做到这一点,以便自动调整字体大小,例如,iPad 为 160,iPhone 5 为 50?
最佳答案
设置wR hR
160的字体大小。要处理指定设备的字体,您应该捕获iPhone设备型号。
如果 Storyboard中有适用于 iPad/iPhone 的 UITextField,您应该关心约束。
或者使用下一个代码,例如,在 func textFieldDidEndEditing(_ textField: UITextField)
中:
textField.adjustsFontSizeToFitWidth = true
或者在这里:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
textField.adjustsFontSizeToFitWidth = true
return true
}
关于swift - 如何根据文本字段的大小调整字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55826808/