如何使字体缩放
我正在为 iPhone 和 iPad 制作一个通用应用程序。我知道有一个选项可以定义文本太大时应向下缩放到选定的点大小,但是当文本在 iPad 上显示时我需要文本向上缩放。这可能吗?我有一个尺寸为 18 点的标签。考虑到文本的长度,这几乎占据了 iPhone 的整个宽度。但在 iPad 上,由于屏幕尺寸增大,情况不会如此……
感谢您的宝贵时间。
I am making an universal application for iPhone and iPad. I know there is a option to define that the text should scale downwards to a chosen point-size when it is to large however I need the text to scale upwards when the text is shown on the iPad. Is that possible? I have a label with a size of 18 points. This almost occupy the whole width on the iPhone with the length of the text in consideration. But on iPad this will not be the case because of the increased size of the screen...
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在通用应用程序上遇到了同样的问题。
我确实设置了自动调整大小参数以直接在 Interface Builder 中缩放所有组件,但它没有缩放字体大小以占用新给定的屏幕空间。
我最终使用下面的代码更新了每个视图的 viewDidLoad ,基本上是迭代视图的组件并将所有标签的 pointSize 加倍(对于按钮也可以这样做)
:现在从 iPhone 到 iPad 都很好。
I had the same issue on a universal App.
I did set the autosizing parameters to scale all components directly in Interface Builder but it wasn't scaling the font size to take the newly given screen space.
I ended up updating the
viewDidLoad
of each view with the code below, basically iterating through the component of the view and doubling the pointSize for all labels (can do as well for buttons):The app does scale up nicely from iPhone to iPad now.
您可以循环该方法:
直到获得占据两行的匹配项,然后使用以前的字体大小。仅使用惯用语来定义 iPad 的特定尺寸似乎更快/更容易。
You could loop on the method:
until you get a match that takes up two lines, then use the previous font-size. Seems quicker/easier to just use idioms to define a specific size for the iPad.