簡體   English   中英

如何根據文本字段的大小調整字體大小?

[英]How can I adjust the font size according to the size of the text field?

我想要一個文本字段來填寫用戶的名稱和調整大小的工作,但字體大小不會隨之改變。 我該怎么做才能調整字體大小,例如,iPad為160,iPhone 5為50?

https://imgur.com/8nAQUGJ

https://imgur.com/00AA5B7

設置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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM