简体   繁体   中英

How to Know the maximum font size allowed for a given font name?

Is there any way to know the maximum size a font allowed.

I am doing

textInputTextView.font = [UIFont fontWithName:currentFontName size:doubleFontSize];
frame.size = textInputTextView.contentSize;

For different fonts I am getting wrong contentSize when doubleFontSize is more than 70. For some fonts I get wrong contentSize when doubleFontSize variable is only 40.

I am guessing textView.font = doubleSizeFont is too big for those particular fonts. All are ok when font size is small between 10 to 30.

Is there any way to know the maximum size allowed by a particular font?

Details:

I need an image from UITextView . I am using UIGraphicsGetImageFromCurrentImageContext image is producing ok. But I realized image quality is low. So I tried to make the TextView frame and font double.

When I Write in big font "I am a good boy" if good is the right most word. I get "I am a boy" the right most word good disappears I get some blank space on right side of the image. How tragic :)

You Can Calculate height/Width of the content by using the following code.Then resize your frame. Here my Width is fixed (290) and Calculating the height.

CGSize strSize= [DataToBeDisplayed sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:CGSizeMake(290.0,99999.0)];
frame.size.height = strSize.height

I believe the issue that you are having is because you are using an UITextView . Text views inherits from the UIScrollView so it would not decrease the size of your font, it would only adapt its contents size and make your text scrollable.

Use an UITextField instead which also inherits from the UIView (thus can be used as an image) but allows for greater control. Fix its size to the maximum you would like it to be on screen and then working with both the [mylabel adjustsFontSizeToFitWidth:Y/N] and the [mylabel setminimumfontsize:somefontsize] methods, constrain it if too much text is entered. This will yield you a crisp big font and dynamically fit it upon input

~/End of Line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM