0

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

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

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

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

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

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

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

4

2 回答 2

2

我现在不在我的 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
于 2012-11-19T20:59:50.827 回答
0

这就是我实现它的方式

CGFloat fontSize = self.label1.font.pointSize;
CGFloat fontSize1 = self.label2.font.pointSize;
CGFloat fontSize2 = self.label3.font.pointSize;
NSArray *numbers = @[[NSNumber numberWithFloat:fontSize],[NSNumber numberWithFloat:fontSize1],[NSNumber numberWithFloat:fontSize2]];
float xmax = -MAXFLOAT;
float xmin = MAXFLOAT;
for (NSNumber *num in numbers) {
    float x = num.floatValue;
    if (x < xmin) xmin = x;
    if (x > xmax) xmax = x;
    NSLog(@"lowest number = %f",xmin);
于 2015-01-13T11:14:33.440 回答