0

I have an UILabel in my iPhone app. I want to show large sentence in UILabel in a single line. That means I want to decrease the font size and show the full text in a visible area. I don't want to show it in multiple lines. Can anyone please help me to do this?

My code is:

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; 

Any one please help me to do this? Thanks in advance.

8vius
  • 5,786
  • 14
  • 74
  • 136
Gopinath
  • 5,392
  • 21
  • 64
  • 97
  • That bit about [`textViewLabel.numberOfLines`](http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/numberOfLines) might be important. – rickster Jul 20 '12 at 05:27
  • May be this similar question would help you out!! [Font Size][1] [1]: http://stackoverflow.com/questions/4382976/multiline-uilabel-with-adjustsfontsizetofitwidth – Nina Jul 20 '12 at 05:38

3 Answers3

3

change numberOfLines property from

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

to

textViewLabel.numberOfLines = 1;

add

textViewLabel.adjustsFontSizeToFitWidth = YES; 

Conside setting

textViewLabel.minimumFontSize = someValue; // default is 0.0
Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
shahid-rasheed
  • 509
  • 2
  • 8
1

Try this property:

myLabel.adjustsFontSizeToFitWidth = YES;
N C
  • 539
  • 2
  • 13
1

try this :

[textViewLabel  setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
Ashutosh Dubey
  • 385
  • 1
  • 4
  • 14