0

我的 iPhone 应用程序中有一个 UILabel。我想在一行中显示 UILabel 中的大句子。这意味着我想减小字体大小并在可见区域显示全文。我不想在多行中显示它。谁能帮我做到这一点?

我的代码是:

textViewLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 5, 194, 20)];
textViewLabel.text = @"I have an UILabel in my iPhone app. I have want";
textViewLabel.textColor = [UIColor lightGrayColor];
textViewLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
textViewLabel.numberOfLines = 0;
textViewLabel.backgroundColor = [UIColor clearColor];

CGSize maximumLabelsize2 = CGSizeMake(194,20);
CGSize expectedLabelsize2 = [result sizeWithFont:textViewLabel.font constrainedToSize:maximumLabelsize2 lineBreakMode:textViewLabel.lineBreakMode]; 
CGRect messagesFrame = textViewLabel.frame;
messagesFrame.size.height = expectedLabelsize2.height;
textViewLabel.frame = messagesFrame; 

任何人请帮我做到这一点?提前致谢。

4

3 回答 3

3

更改 numberOfLines 属性

textViewLabel.numberOfLines = 0; // 0 means as many lines as needed

textViewLabel.numberOfLines = 1;

添加

textViewLabel.adjustsFontSizeToFitWidth = YES; 

考虑设置

textViewLabel.minimumFontSize = someValue; // default is 0.0
于 2012-07-20T05:40:02.130 回答
1

试试这个属性:

myLabel.adjustsFontSizeToFitWidth = YES;
于 2012-07-20T05:21:42.397 回答
1

试试这个 :

[textViewLabel  setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
于 2012-07-20T05:25:52.707 回答