如果UILabel包含太多文本,如何设置标签以缩小字体大小?
这是我设置UILabel的方法:
descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 30, 130, 150)];
[descriptionLabel setFont:[Utils getSystemFontWithSize:14]];
[descriptionLabel setBackgroundColor:[UIColor clearColor]];
[descriptionLabel setTextColor:[UIColor whiteColor]];
descriptionLabel.numberOfLines = 1;
[self addSubview:descriptionLabel];
最佳答案
descriptionLabel.adjustsFontSizeToFitWidth = YES;
descriptionLabel.minimumFontSize = 10.0; //adjust to preference obviously
以下示例已在iPhone Simulator 3.1.2上进行了测试和验证:
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 0, 200, 30)];
descriptionLabel.font = [UIFont systemFontOfSize:14.0];
descriptionLabel.minimumFontSize = 10.0;
descriptionLabel.adjustsFontSizeToFitWidth = YES;
descriptionLabel.numberOfLines = 1;
descriptionLabel.text = @"supercalifragilisticexpialidocious even thought he sound of it is something quite attrocious";
关于iphone - 如何使UILabel中的文本缩小字体大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2685735/