自定义安装的字体在UILabel中显示不正确 [英] Custom installed font not displayed correctly in UILabel

查看:389
本文介绍了自定义安装的字体在UILabel中显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Adobe Font Collection Pro包中的 Helvetica Neue Condensed 字体。不幸的是,当我在 UILabel 中使用它时,似乎绘制不正确。



行高似乎被计算正确(我认为),但是当字体显示时,它是对齐到边界框的最顶部。我调用了 [myLabel sizeToFit] ,并且只调整了宽度以产生这个屏幕截图:



我有同样的问题粗体和普通版的字体。我能够从OSX中拉取 Helvetica Neue Bold 版本,并将其放在我的设备上,并显示正常(上图中的绿色背景)。



可能是错误的字体文件或我的代码,会导致这样画?

解决方案

我发布了一个解决方案,包括修补ttf字体文件这里

类似的问题在上讨论过,自定义安装的字体在UILabel 。没有给出解决方案。

下面是在我的自定义字体工作的解决方案,在UILabel,UIButton等有相同的问题。与字体的问题原来是它的上行属性相比系统字体的值太小。 Ascender是字体字符上方的垂直空格。要修复您的字体,您必须下载 Apple Font Tool Suite 命令行工具。然后把你的字体,并执行以下操作:

 〜$ ftxdumperfuser -t hhea -A d Bold.ttf 

这将创建 Bold.hhea.xml 。用文本编辑器打开它,并增加 ascender 属性的值。你将不得不尝试一下,找出最适合你的确切值。在我的情况下,我将它从750更改为1200.然后使用以下命令行再次运行该实用程序,将您的更改合并回到ttf文件中:

 〜$ ftxdumperfuser -t hhea -A f Bold.ttf 

然后只要使用导致您的应用程序ttf字体。


I'm trying to use a Helvetica Neue Condensed font which I got from the Adobe Font Collection Pro Package. Unfortunately, it seems to draw incorrectly when I use it within a UILabel.

The line height seems to be calculated correctly (I think), but when the font is displayed, it is aligned to the very top of the bounding box. I called [myLabel sizeToFit] and only adjusted the width to produce this screen capture:

I had the same problem with both the bold and regular version of the font. I was able to pull a version of Helvetica Neue Bold from OSX and put it on my device and it displays fine (green background in above picture).

What could be wrong with the either the font file or my code that would cause it to draw this way?

解决方案

I posted a solution that involves patching ttf font file here:

A similar problem was discussed at Custom installed font not displayed correctly in UILabel. There was no solution given.

Here's the solution that worked for my custom font which had the same issue in UILabel, UIButton and such. The problem with the font turned out to be the fact that its ascender property was too small compared to the value of system fonts. Ascender is a vertical whitespace above font's characters. To fix your font you will have to download Apple Font Tool Suite command line utilities. Then take your font and do the following:

~$ ftxdumperfuser -t hhea -A d Bold.ttf

This will create Bold.hhea.xml. Open it with a text editor and increase the value of ascender attribute. You will have to experiment a little to find out the exact value that works best for you. In my case I changed it from 750 to 1200. Then run the utility again with the following command line to merge your changes back into the ttf file:

~$ ftxdumperfuser -t hhea -A f Bold.ttf

Then just use the resulting ttf font in your app.

这篇关于自定义安装的字体在UILabel中显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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