Suresh Varma
Suresh Varma

Reputation: 9740

Count number of lines in textView

I am developing an application where i need to charge the user based on the number of pages. Can anyone tell me how can i derive number of pages if the data is entered as multiline in textView. Thanx in advance

Upvotes: 1

Views: 1081

Answers (2)

rspl123
rspl123

Reputation:

Try this piece of code it works fine

 -(float)getHeightByWidth:(NSString*)myString:(UIFont*)mySize:(int)myWidth

 {

CGSize boundingSize = CGSizeMake(myWidth, CGFLOAT_MAX);
CGSize requiredSize = [myString sizeWithFont:mySize constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];  
return requiredSize.height;
}

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135550

You can use NSString's -sizeWithFont:constrainedToSize:lineBreakMode: method to calculate the space a given amount of text would occupy.

Upvotes: 3

Related Questions