字形的高度

我有2个属性字符串表示'A'和'。'

我需要计算每个字符串的高度。 目前返回的高度对于两者都是相同的,它似乎返回给定字体中最高字符的最大可能高度(即使该字符不存在于字符串中)。

我想要获得每个字符的确切像素高度,以便我可以调整它们周围的适合字符(字形)的视图。 我试过使用CTFramesetterSuggestFrameSizeWithConstraints()和CTLineGetTypographicBounds(),但它返回一个类似于属性字符串大小方法的数字。

希望有关如何去做这件事的任何提示!


到最后,你可以这样做:

// Create an attributed string
CTLineRef line = CTLineCreateWithAttributedString(_string);

// Get an array of glyph runs from the line
CFArrayRef runArray = CTLineGetGlyphRuns(line);

// loop through each run in the array      
CTRunRef run = ....

// Get the range of the run         
CFRange range = CFRangeMake...

// Use CTRunGetImageBounds                                  
CGRect glyphRect = CTRunGetImageBounds(run, context, range);

// glyphRect now contains the bounds of the glyph run, if the string is just 1 character you have the correct dimensions of that character.
链接地址: http://www.djcxy.com/p/81923.html

上一篇: Height of glyph

下一篇: How to hide UINavigationBar 1px bottom line