Reputation: 9740
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
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
Reputation: 135550
You can use NSString's -sizeWithFont:constrainedToSize:lineBreakMode:
method to calculate the space a given amount of text would occupy.
Upvotes: 3