Change the height of individual characters using core text

I have a font where unfortunately the numbers and letters are different heights. I need to display a reference code which is a mix of letters and numbers and the uneven heights of the characters looks jarring. Is it possible with core text (or another technology on iOS) to render certain characters with a slightly stretched height so that it looks even numbers and letters are displayed together.

Eg i have the string '23Rt59RQ' I need the 2,3,5,9 to be rendered with a larger height.


AFAICT, there's nothing in the CGContext API (which is what you'd want to use for laying out sets of glyphs) which would directly, easily facilitate this.

If it's really very important to use the font you are using, you could make separate calls to CGContextShowGlyphsAtPositions for alphabetic and numeral characters, calling CGContextSetFontSize each time so that the end result ends up matching, but this is a lot of overhead for just drawing text, and will probably result in undesirable performance.

My real advice would be to pick a better font so that this isn't even an issue :)


In the end of used regex to identify the character groups and then created an attributed string varying the font size in the font given in the NSFontAttributeName attribute according to which characters were to be displayed.

Kinda hacky but it had the desired effect.

链接地址: http://www.djcxy.com/p/81928.html

上一篇: 核心文本字形位置

下一篇: 使用核心文本更改单个字符的高度