apple 0.31414 (Label1)
banana 0.41253 (Label2)
kiwi 0.2312 (Label3)
On iOS, however, the width of a single letter is not uniform, as in this case(Editor, not this screen). It is different when it is in uppercase or lowercase, and when it is 0 or 1. I want to do the beginning of the text and the beginning of the number at the same position.
I tested it with several built-in fonts on iOS, but I could not match the position of letters and numbers.
Related
I noticed that UILabel doesn't wrap words fairly. It glues the last short word (10 or less characters) to the previous one and moves them together on the second line.
Check the illustration:
Label #1: There is enough room in the first line for word 'seven' (as expected).
Label #2: One more 'short' word added and word 'seven' migrated to the second line (I'd like to avoid this behaviour).
Label #3: The last word contains 10 characters and still is treated as 'short' by the Label.
Label #4: The last word contains 11 characters and is now detached from word 'seven' that goes back to the first line (as expected).
Seemingly, Apple fights with 'widows' and forces to a 'good typography' by this behaviour. But sometimes I don't need such care. So, how can I prevent UILabel from glueing last words to the previous one?
Fixed by using NSAllowsDefaultLineBreakStrategy set to false.
Most fonts on iOS/macOS are proportional and the typeface system attempt to use good typography standards. Therefore the characters and/or typography will change the spacing based on other characters around it, line length etc. To get more predictable text display, use a font that has fixed spacing like Monaco or other fixed spacing fonts. This will produce a much more predictable display.
Here is Apple's Typography guidelines to start at:
https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/
I love the San Francisco font. And would like to use it if possible. I have a table view that shows a series of labels where each label is 6 hexadecimal digits, e.g.
F0:1A:2B
12:CE:88
The problem is that they don't line up nicely. I can enable the monospaced digits attribute for the font, but that doesn't account for the characters ABCDEF. I've tried the single monospace font (Menlo) and it looks terrible and out of place.
I'm toying with making 8 little labels one for each character (6 hex digits plus the two : separators), which seems like a huge kludge. Is there no other way. I wondered if there was a way to do something with AttributedString to get the hex digits to be same width?
If you want to use a proportionally spaced font, you'll have to draw the characters at the appropriate places. Otherwise, find a monospaced font you like.
For completeness sake, I should post what I ended up doing after accepting what #AaronBratcher confirmed.
First I created 5 separate UILabels for the following elements:
leftTwoDigits-leftSeparator-centerTwoDigits-rightSeparator-rightTwoDigits
I used constrains to constrain all of their baselines, and have 0 horizontal spacing betwixt each. The separator labels were set simply to : and normal color. The xxxTwoDigits labels were given the string AA. A is NOT the widest character, C is. But A is near it. C is too wide, and A is wide enough. The color of these labels was set to clear so it doesn't actually show up.
Then 6 more UILabels are added. Again the the same baselines. The first two are constrained to the leading and trailing sides of leftTwoDigits and constrained to match in width. Repeat for the other 4 cells. Make all centered. And populate them individually with the individual digits.
Why the display of Unicodes for superscripts of digits are not at the same height? This is specially noticeable if you make two digit numbers out of the superscript digits. Some of them look fine but the rest look out of the place with respect to each other. Am I missing something? Or is this how it is?
Like jrturton mentions, ¹, ² and ³ were from a legacy character set (Latin 1) and therefore included in a different place. This also means that lots of fonts don't have support for more superscript numbers, as many only strive for Latin, Greek and Cyrillic with a few punctuation symbols thrown in. So the remaining ones are taken from a different font over which you as an author have little to no control.
As an example:
Those are the superscript numerals from 1 to 9 and 0. The run of text was formatted in Arial in Word. You see what happened to the rest of them. Contrary to what jrturton believes, there is no reshaping of existing glyphs involved. This is just font substitution.
The out of place ones (1,2 and 3) were added before the rest (see wikipedia: http://en.wikipedia.org/wiki/Unicode_superscripts_and_subscripts), and are from a different unicode block. That doesn't explain why they look different but it may be that those ones are actual characters in most fonts, and the remaining ones are just adjusted versions of the standard glyphs.
This appears to be how it is and you are right, it looks terrible when you are trying to make multi digit superscript numbers. I don't know if it applies to all fonts but it is very noticeable on the iOS system font.
If anyone has a way to make this work, I will put a bounty up on this question.
UPDATE
I knocked up a little program to cycle through all fonts on the phone and display the superscript numerals from 0 to 9. The following fonts had a consistent appearance across all digits:
Zapfino
Courier-Bold
AmericanTypewriter (also -Bold)
HiraKakuProN-W6 (also -W3)
Noteworthy-Bold (also -Light)
I'm drawing a bingo card (UIView) with 27 squares: 9 columns x 3 lines. Cards can have 3 different sizes, so they must be resizable. And inside the card, every square with a number is an UIView with a custom class. Inside the view (in the .xib file) there is the UILabel, where the number is set with:
[lblNumber setText: [NSString stringWithFormat:((number < 10) ? #" %i" : #"%i"), number]];
When numbers have two digits (10->90) everything looks great inside the squares, but for numbers from 1 to 9, label displays with a bigger font size than the others because it only has 1 digit.
Ok, I tried to uncheck the "Adjust to fit" setting, but then font size remains small.
Autosizing settings of the label are set to both arrows, so the label has "space" to resize.
¿How can I have single digit numbers to resize the exact proportion than numbers with two digits?
As you can see in the line of code, I also tried to concatenate a space for numbers with one digit.
Thanks in advance.
In this sample code, the author does the following
\draw ($(closedStart.south) + (-.5em,0)$)
edge[stateEdge] node[edgeLabel, xshift=-3em]{\emph{Passive open}}
($(listen.north) + (-.5em,0)$);
What irritates me most about these markup based drawing tools is that I've to measure a value and specify. In this case, the author specifies .5em
I've yet not understood how to figure that out? How much is .5em? I don't even know the size of the base object, so how can I be sure that if I give a value it will be valid?
Is there any approach to do this? How should I decide the value and also the unit? Is em always the best unit to use?
Google is your friend: http://en.wikipedia.org/wiki/Em_%28typography%29
An em is a unit of measurement in the field of typography, equal to the point size of the current font. This unit is not defined in terms of any specific typeface, and thus is the same for all fonts at a given point size. So, 1 em in a 16 point typeface is 16 points.
You can change the unit of measurement to anything supported by latex, i'm sure: in, mm, cm, pts, picas, etc etc.
Not too sure how TikZ handles it but in LaTeX you can specify measurements as fractions (larger or smaller than 1) of known lengths, so you could set a length to be, say, 0.5\textwidth. My bet is that TikZ has this sort of facility so if you are going to be a long term user you'll want to figure it out.
To expand on what Mica says:
ems are the usual way that intercharacter space is measured, and is historically was the width of a character "M" in a given font ("M" normally being the widest letter in Latin-based fonts): crucially, it is a relative measure, and subscript fonts, say, have a smaller em than normal text. Modern fonts generally have narrower "M" characters than historically, and there are many non-Latin fonts, so the em measure is now derived from the dimensions of the square (or oblong) that the font designer places the character in, and is communicated as a parameter, together with such facts as the height of the baseline that text sits on, that tells us the scale of the font.
The point size of a font is the number of points (usually 1/72 inch) to an em, so a 12 point font is one whose character "M" is 1/6th of an inch wide (i.e., 12/72 in). The subscripts of a 12 point font are usually shown in a 7 point font, for which the em is just under 1/10th inch.
If you want to do positioning on a page, use points. If you want to control spacing in text, use ems because they scale.
Postscript
Fixed the discussion of the character `M', thanks to Mica.