iOS:调整所有 UILabel 字体的大小以匹配

标签 ios cocoa-touch uilabel autoresize

我有几个用文本填充的 UILabel。

UILabel 中的所有字体都设置为自动收缩。

如果其中一个 UILabel 包含太多文本(并且必须自动调整大小),我该如何更改剩余的 UILabel 字体大小以匹配已调整大小的字体大小?

在我的代码末尾,我使用了以下内容:

 if (self.label.font.pointSize < 16){

        labelTwo.font = [UIFont fontWithName:@"Noteworthy-Bold" size:self.label.font.pointSize];

我的默认字体大小是 16,所以我正在检查字体大小是否已减小。

最佳答案

我现在不在我的 Mac 旁,所以我无法为您编写实际代码,但我可以为您伪造它,以便您知道前进的方向。

Create a variable to store the smallest font size.
Foreach for each UILabel in the view.
Get the font size.
Check the font size against the smallest known so far.
    If the font size is smaller than the smallest known, save it.
    Else, disregard.
After all UILabels in view have been checked go back through them, and set the font size to that of the saved value

关于iOS:调整所有 UILabel 字体的大小以匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13462032/

相关文章:

适用于所有屏幕和方向的 iOS

iOS 无法执行 HTTP GET 请求 -Error Domain=NSURLErrorDomain Code=-1012

ios - 如何到达父对象中的主类?

ios - 找不到体系结构 i386 错误 iOS 的符号

ios - NSTimer 类方法和失效

ios - 为什么 UISlider 更新 Cocoa-Touch 中的值很慢?

iphone - 在 iPhone 项目中加载数据文件

ios - 如何计算具有右/左详细样式的 tableviewcell 的高度?

ios - UILabel - 如何在 Swift 3 中的行之间添加空格

iOS 添加带有动画句号的加载文本