I want a text field to fill in the users' name and the resizing works, but the font size does not change with it. How can I do this so the font size gets adjusted, for example, 160 for an iPad and 50 for the iPhone 5 automatically?
Set font size for wR hR
160. To handle font for specified device, you should catch iPhone device model.
You should care about constraints if UITextField for iPad/iPhone in Storyboard.
Or use next code, for example, in func textFieldDidEndEditing(_ textField: UITextField)
:
textField.adjustsFontSizeToFitWidth = true
Or here:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
textField.adjustsFontSizeToFitWidth = true
return true
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.