3

Here is the text present in my UILable...

"This list isn’t actually based on a straight popularity count; simply tallying the most-read verses results in a top 100 list that consists almost entirely of John 3:16 and verses from 1 Corinthians 13, Genesis 1, Romans 8, and Psalm 23. Our list instead considers instances in which BibleGateway.com users looked at three or fewer verses at one time."

How do i get the final line of text..ie.,"at three or fewer verses at one time." from my uilable.

Any solution is greatly appreciated.

Master Stroke
  • 5,108
  • 2
  • 26
  • 57
  • What you mean by line??Is it last sentence or a last few words – Rose Jan 18 '13 at 06:57
  • 1
    see this - [How to get text from nth line of UILabel?](http://stackoverflow.com/questions/4421267/how-to-get-text-from-nth-line-of-uilabel/14413484#14413484) – TheTiger Jan 19 '13 at 10:59

1 Answers1

2

I can give one idea . May this will help you.

 UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,50,200,350)];
    myLabel.numberOfLines = 0;
    myLabel.lineBreakMode = UILineBreakModeWordWrap;
    myLabel.text = @"This is some text in a UILabel which is long enough to wrap around the lines in said UILabel. This is a test, this is only a test.";
    [self.view addSubview:myLabel];
    CGSize labelSize = [myLabel.text sizeWithFont:myLabel.font 
                                constrainedToSize:myLabel.frame.size 
                                    lineBreakMode:UILineBreakModeWordWrap];
    CGFloat labelHeight = labelSize.height;
    NSLog(@"labelHeight = %f", labelHeight);
    [myLabel release];

with above you can get height of label, then you can get the # of lines by dividing the height with some appropriate number which depends on the font size.

1) After this Get NSAttributedString from your UILabel. 2) From NSAttributedString you can get "\n" characters. 3) get last "\n" and extract value from this index to last index.

Neelam Verma
  • 3,232
  • 1
  • 22
  • 33