测量NSString中每个字符的大小 [英] Measure size of each char in an NSString

查看:44
本文介绍了测量NSString中每个字符的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有[NSString sizeWithFont:],它返回整个字符串的大小.

We have [NSString sizeWithFont:] which returns the size of the entire string.

如何获取字符串中每个字符的大小的数组?

What about getting an array of the sizes of each individual character within the string?

您将如何做(除了标记字符串并为每个字符串调用sizeWithFont之外)?

How would you do that (besides tokenizing the string and calling sizeWithFont for each)?

最好,万斯

推荐答案

您应该能够获取有关单个字形的大小信息(请注意,尽管这些字形并不总是与字符串中的单个字符一对一地映射)通过使用Core Graphics函数 CGFontGetGlyphBBoxes .

You should be able to get size information about individual glyphs (note though that those don't always map one-to-one with individual characters in a string) by using the Core Graphics function CGFontGetGlyphBBoxes.

这篇关于测量NSString中每个字符的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆