UITextField最小字体大小 [英] UITextField minimum fontsize

查看:590
本文介绍了UITextField最小字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用该属性 minimumFontSize

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

但文本永远不会达到最小字体大小10,它会被截断,但如果我改变了当前fontSize为10,整个文本显示正确。我使用这个属性错了吗?

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?

推荐答案

到目前为止......你正在设置你的 UITextField 正确,而 adjustsFontSizeToFitWidth 一般都有效,但我相信iOS正处于不足之处。

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.

UITextField 中的文字不会自动缩小超过 14 pts * - 无论你设置 minimumFontSize 小于该值,例如10分的合理要求。

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:


  • 字体大小17,如果需要,最小尺寸15将降至15

  • 字体大小17,最小尺寸10只会降至14

  • 字体大小13,最小尺寸4将保持在13

您可以通过将三个 UITextField 并排比较的文本字符串来测试这个问题,其中最小的字体尺寸分别为13,14和15。前两个将显示完全相同,为14分。

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.

这似乎是一个奇怪的幻数,但你去了。铁腕可读性考虑因素?我想您可以尝试自己调整字体大小或生活在 minimumFontSize = 14

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.

*我在IB中对此进行了验证,但它肯定适用于以编程方式创建的 UITextField s也是。

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

这篇关于UITextField最小字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆