Ram Mohan Chaurasiya
Ram Mohan Chaurasiya

Reputation: 41

How to find the number of characters that a UILabel can Hold?

I am trying to find the number of characters that a UILabel can hold. I am using

lbl_Text = [[UILabel alloc]initWithFrame:CGRectMake(0,15,290,320)];
lbl_Text.lineBreakMode = UILineBreakModeWordWrap;
lbl_Text.numberOfLines = 20;
lbl_Text.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];

to set the font and font size. Can anyone find the number of characters that this UILabel can hold ?

Upvotes: 2

Views: 1190

Answers (1)

user189804
user189804

Reputation:

You can check the size of a particular string in a particular font with NSString's sizeWithFont: method. You can't ask "how many characters can I fit?" because in a proportional spaced font like Helvetica all the characters occupy different widths. Typically you know exactly what you need to display but size can vary, so you can check sizes with successively smaller fonts until you find the size that fits (which is why some of the native controls will automatically do this for you).

Upvotes: 1

Related Questions