0

I want to calculate number of lines and find all characters in the first line of the UILabel dynamically from given text. I'm using wordwrapping for uilabel. Is it possible. Please help and guide me.

Goutham
  • 299
  • 1
  • 24
  • 1
    This may helps you: http://stackoverflow.com/questions/4421267/how-to-get-text-from-nth-line-of-uilabel – A J Feb 24 '14 at 11:20

1 Answers1

0

try like this

UILabel *thisyourlabel = [[UILabel alloc] initWithFrame:CGRectZero];
        thisyourlabel.numberOfLines = 0;
        thisyourlabel.lineBreakMode = UILineBreakModeWordWrap;  
        thisyourlabel.text = @"I want to calculate number of lines and find all characters in the first line of the UILabel dynamically from given text. I'm using wordwrapping for uilabel. Is it possible. Please help and guide me";

        CGRect frame = thisyourlabel.frame;
        frame.size.width = 200.0f;
        frame.size = [thisyourlabel sizeThatFits:frame.size];
        thisyourlabel.frame = frame;

        CGFloat lineHeight = thisyourlabel.font.leading;
        NSUInteger linesInLabel = floor(frame.size.height/lineHeight);
        NSLog(@"Number of lines in label: %i", linesInLabel);

        [self.view addSubview: thisyourlabel];
Sport
  • 8,570
  • 6
  • 46
  • 65