![](/img/trans.png)
[英]How to adjust font size of a label according to length of string and label size
[英]How can I adjust the font size according to the size of the text field?
我想要一個文本字段來填寫用戶的名稱和調整大小的工作,但字體大小不會隨之改變。 我該怎么做才能調整字體大小,例如,iPad為160,iPhone 5為50?
設置wR hR
160的字體大小。要處理指定設備的字體,您應該捕獲iPhone設備型號。
如果在Storyboard中使用UITextField for iPad / iPhone,你應該關心約束。
或者使用下一個代碼,例如,在func textFieldDidEndEditing(_ textField: UITextField)
:
textField.adjustsFontSizeToFitWidth = true
或者在這里:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
textField.adjustsFontSizeToFitWidth = true
return true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.