UITextField minimum fontsize

南楼画角 提交于 2019-12-17 19:59:19

问题


I'm using the property minimumFontSize

textField.font = [UIFont boldSystemFontOfSize:17];
textField.textColor = [UIColor darkGrayColor];
textField.minimumFontSize = 10;
textField.adjustsFontSizeToFitWidth = YES;

But the text never goes to minimum font size of 10, it gets truncated, but if I change the current fontSize to 10, the whole text appears correctly. Am I using this property wrong?


回答1:


As late as it is ... you were setting up your UITextField correctly, and adjustsFontSizeToFitWidth does work in general, but I believe iOS is being underhanded.

It appears text in a UITextField will not automatically shrink beyond 14 pts* - no matter if you set minimumFontSize to less than that value, such as your reasonable request of 10 pts.

A UITextField with:

  • Font size 17, minimum size 15 will go down to 15 if need be
  • Font size 17, minimum size 10 will only go down to 14
  • Font size 13, minimum size 4 will stay at 13

You can test this by comparing three UITextFields side by side with strings of text far too long for them, where the minimum font sizes are 13, 14 and 15 respectively. The first two will appear exactly the same, at 14 pts.

It seems an odd magic number, but there you go. Iron-fisted readability considerations? I suppose you could try adjusting the font size yourself or living with having minimumFontSize = 14.

*I verified this in the IB but it will surely apply to programmatically created UITextFields too.




回答2:


The font will get truncated until the minimum font size. To experiment with this, drag a UILabel in Interface Builder, set the properties in there and change the width of the UILabel to see the effect.



来源:https://stackoverflow.com/questions/6045176/uitextfield-minimum-fontsize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!