Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

ios - UITextField minimum fontsize

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...