我如何使文本在UILabel收缩字体大小 [英] How can I make text in a UILabel shrink font size
本文介绍了我如何使文本在UILabel收缩字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果UILabel包含太多文本,我该如何设置我的标签以缩小字体大小?
If a UILabel contains too much text, how can I setup my label so that it shrinks font-sizes?
这是我设置UILabel的方法:
Here is how I am setting up my 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上测试和验证: / p>
The following example is tested and verified on 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";
这篇关于我如何使文本在UILabel收缩字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文