Why is lineHeight of UIFont larger than font size?

KudoCC

I use the code below to calculate the number of lines of string with limited width.

NSString *text = @"abcdefgh";
UIFont *font = [UIFont systemFontOfSize:15.0];
CGFloat h = [text suggestHeightWithFont:font width:320.0];
NSInteger lines = (h > font.lineHeight) ? h/font.lineHeight+1 : h/font.lineHeight;
NSLog(@"height %f, %f, number lines:%ld", h, font.lineHeight, (unsigned long)lines);

But I found that font.lineHeight (log shows it is 17.900391) is larger than the font size which is set as 15.0.

The log message shows:

height 17.900391, 17.900391, number lines:1

Daij-Djan

lineHeight = a font's ascender (part of a letter that is above)
                  + a font's descender (so below baseline)
                  + a font's leading (vertical spacing)

e.g. for font size 10
A might have ascender=10, descender=0
g might have ascender=5, descender=4

lineHeight = 14 + leading ... 14,5 maybe


Note that the numbers here were random and only given to better illustrate the issue

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

UIFont: Font size differs

input element height larger than font size

Why does text with a larger font-size show up lower than other text and how to stop it?

Why UIFont(descriptor:size:) is x200 slower than UIFont(name:size:)?

Why the tuple has a larger size than expected?

Why is the size of a pointer to something on the heap larger than the size of a stack variable?

Why is the div bigger than the font-size?

Why are image sequences larger (in size) than the source videos?

Why is Java 6 compiled class size larger than Java 5?

Why is the resident set size (RSS) of my program larger than the executable?

Can I generate an anti-aliased font size larger than 149?

Android: Font size can't be larger than 717px in a text box on any device

BooleanArray with size larger than 2147483647

Why is 1em shorter than the default font size?

Why does winfo_width() return a larger size of button widget than the size of what it exactly looks like?

Why a partitioned table size is larger than a normal table size with the same data

Why is exFAT's "Size on Disk" larger than that of NTFS when they both have the same allocation unit size?

is mobile viewport size larger than screen size?

Why on declaring an array global in c++, the size that it can be given is larger than declaring it in main

Why is my Java socket receiving an array size larger than what was sent?

Why the size of base64-encoded string is larger than the original file

Why does saving mat files with scipy result in larger file size than with Matlab?

Why is my Huffman Compression making the Compressed output a larger size than my original text?

HDD backups are larger than physical disk size

How to sum the array if it is larger than a given size

List files larger than {size} sorted by date

Problems using newpad with a size larger than the screen

Row larger than the maximum allowed size

SQL Server: Record size larger than expected