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.
Asked
Active
Viewed 788 times
1 Answers
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