What is the relation between zebra font 0 font size parameters and actual text size in dots? - font-size

I create a text in ZPL format using zebra font 0, which is a scalable font. I need to calculate the text width and height, however I didn't know the relation between ZPL font parameter and letter size in dots. The ZPL command used to create text are :
^FO15,19^A0,20,20^FDSample_text^FS
The parameter 20,20 supposed to be font height (h) and width(w) in dots on the manual, however when I use font type 0 and test it, the height and width (20,20) not equal to the size of letter in dots.
What is the unit of height and width font parameter for scalable font? Is there a formula to calculate text height and width in dots for all font size input?

Related

Unique multiline UILabel looks using auto layout

I have a multiline UILabel that I'd like to look similar on different devices (iPhone only). If it was a single line, I'd simply place the auto layout constraints and enable Autoshrink and set the Minimum Font Scale.
The height of the label is dynamic is calculated based on text. To do that, I need the font, which should also be dynamic. The hack I could do is place an invisible label, and set the text I want to fit in a single line into it and calculate the font, but it seems too hacky.
Another thing I'm not that familiar with are size classes. But from what I've read, the same class is shared between all portraits, meaning 3.5, 4, 4.7 and 5.5 inch devices would be bound to the same class, therefore I couldn't use the separate font value?
How would I implement the 'font scaling' for multiline labels so I'm getting similar look on different screen sizes?
If by similar look you mean that the same words appear on each line, I don't think it's possible.
If the label height is dynamic based on the amount of text, the label will simply expand to the height required to show the text with the specified font size.
Font scaling only kicks in when there is not enough space to display the text with the specified font size. Therefore, you must constrain the height or number of lines.
I was able to approximate this using a multiline UILabel with font scale of .5. I set an Equal Heights constraint between it and its superview, with a multiplier of .25. See screenshots below.
In this approach, you would have to dynamically change the Equal Heights multiplier based on the amount of text you have.

Multi-line UILabel with auto layout, how to adjust font size according to content without changing label's frame?

I have a multi-line UILabel, which will display contents at run time, contents may only need 1 line or up to 3 lines.
When there is less contents, I'd like the label using a larger font size, and when there are more contents, I want the label to use multiple lines and smaller font size.
Due to autolayout, I can't set the frame of UILabel, and the frame of the label is unknown until run time, so that it can be compatible with different devices.
Currently I set line number of the label as a fixed number, which will divide contents into multiple lines when there is more contents, but when there is less contents, the single line uses a font size as small as when there is more contents. This is not the best experience.
set num of lines and font scale factor 0.5 or 0.75
If your content is small it would use the occupied lines and font size will be the actual size. When your content grows these properties will check if with actual fontsize the content can be adjusted to all lines or not. if its not adjustable with full size then font will be scalled to adjust in contentview.

UILabel text is not displaying properly

I want to show the text in uilabel. The text is ,000124520.061112782.,3299985343, I have assign line break mode to character wrap and number of lines to 0. But in label first line is displayed only the , and then other characters are displayed in next line. But i want to display the text in two lines only. But it is displayed in three lines. I don't know why , is displayed in first line. Please anyone help me.
You should set the numberOfLines of your UILabel to 1.
When the numberOfLines property of a UILabel is set to 0 the UILabel will render its text over as many lines as it needs - e.g. its infinite. To fix your text to a single line you should therefore set the property to 1.
Obviously your text may not all fit on a single line so you should also set the UILabel's minimumScaleFactor property to allow the UILabel to adjust its font size downward (to the supplied limit) to fit the content into the frame of the label. You will also need to set the UILabel's adjustsFontSizeToFitWidth property to YES.
Further to the above an easy way to calculate the value for the minimumScaleFactor property is to divide the minimum font size by the maximum font size. So, say for example your label's default font size was 12 and you were happy for it to drop to 10, then assign the minimum scale factor as follows:
myLabel.minimumScaleFactor = 10/12.0f;

Adjust UIButton label font ,to screen size

I have buttons that created in code, and their size is in % from the screen size, so
they change their width and height proportionally to the screen .
The only thing that remains in the same size is the font size .
I know there is a way to set minimum font size with :
CAT.titleLabel.font=[UIFont fontWithName:#"Gill Sans" size:12];
CAT.titleLabel.numberOfLines=1;
CAT.titleLabel.minimumFontSize=2; //not good
But, the last row here ,minimum size ,is deprecated ,and so Xcode will not allowed to use it.
So , i was also try to set it to fit to width with :
CAT.titleLabel.adjustsFontSizeToFitWidth=YES;
Which results in different font sizes for buttons with the same width and height , so i can see 10 buttons in the same frame,and different text length but with completely different font size .I guess its width is the same as the text width and not the button frame.width .
Is there other solution to fit the frame ?
You can try using CAT.titleLabel.minimumScaleFactor to set the minimum font size. It takes in a multiplier value against the current font size.

iOS UILabel text of different sizes dynamically loading?

For example I have fixed width label with 4 word text with a fix font size. but when 4 (small )word sentence "this is my car" and other 4 (large)words sentence "elephant most beautiful animal" with same size font.
so small 4 words sentence will be adjusted in fixed label width but bigger word sentence "elephant most beautiful animal" will cause the problem in that UILabel text
How can I dynamically calculate the size of sentence words and adjust font size of text to be fixed in UIlabel.
please guide...
Probably you're looking for the adjustsFontSizeToFitWidth property.
in interface builder click on the label and set the minimum font size. if it is not in interface builder, do this
[Label setAdjustsLetterSpacingToFitWidth:YES];
[Label setMinimumScaleFactor:2];
[Label setAdjustsFontSizeToFitWidth:YES];
these shrink the font size depending on the length of the sentence. The first tightens the letter spacing and the second scales the font down by 2. The 3rd adjusts the font size.

Resources