自定义 Arial-Narrow.ttf 字体集成

发布于 2025-01-01 21:32:37 字数 456 浏览 1 评论 0原文

我在我的应用程序中使用此字体时遇到问题。我已在我的资源中导入了 Arial-Narrow.ttf 文件,并在 info.plist 中添加了名称,如下所示。

<key>UIAppFonts</key>
<array>
    <string>Arial-Narrow.ttf</string>
</array>

现在,每当我尝试使用代码在我的应用程序中使用该字体时,

titleLabel.font = [UIFont fontWithName:@"Arial-Narrow" size:28];

它不起作用。但是,如果我使用相同的过程使用不同的字体,它会起作用。那么任何人都可以解释一下我在这里缺少什么或者我们是否可以在我的 iPhone 应用程序中使用 Arial Narrow 字体。

I am having problem in using this font in my Application. I have imported the Arial-Narrow.ttf file in my resources and also added the name in the info.plist as follow

<key>UIAppFonts</key>
<array>
    <string>Arial-Narrow.ttf</string>
</array>

Now whenever I try to use the font in my app using the code

titleLabel.font = [UIFont fontWithName:@"Arial-Narrow" size:28];

It does not work. However it works if I use a different font with same procedure. So can anybody explain what I am missing here or do we are allowed to use Arial Narrow font in my iphone app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滥情哥ㄟ 2025-01-08 21:32:37

好吧,我找到了解决方案。我使用这个 Library 在我的应用程序中使用 Arial-Narrow 字体。因此,如果任何有相同问题的人都可以使用以下步骤从该库中受益。

1)从我上面提供的链接下载库。
2) 将文件夹 FontLabel(包含其中的所有类)导入到要使用自定义字体的项目中。
3) 将自定义字体(即我的情况下为 Arial-Narrow.ttf)文件导入到资源文件夹中。您不需要在 plist 文件中添加字体文件名。
4) 在您想要使用自定义字体的类中导入标头,如

#import "FontLabel.h"

5) 使用此代码使用您的自定义字体初始化此 FontLabel。

FontLabel *titleLabel = [[FontLabel alloc] initWithFrame:CGRectMake(10, 10, 0, 0) fontName:@"Arial-Narrow" pointSize:28.0f];

您可以探索该库以获取更多功能。

Ok I found a solution. I used this Library to use Arial-Narrow font in my app. So if anyone having the same problem can benefit from this library using the following steps.

1) Download the Library from the link I provided above.
2) Import the folder FontLabel (with all the classes in it) into your project where you want to use the custom font.
3) Import the custom font (i.e Arial-Narrow.ttf in my case) file into Resource folder. You don't need to add the fonts file names in your plist file.
4) Import the header in your class where you want to use the custom font like

#import "FontLabel.h"

5) Use this code to initialize this FontLabel with you custom font.

FontLabel *titleLabel = [[FontLabel alloc] initWithFrame:CGRectMake(10, 10, 0, 0) fontName:@"Arial-Narrow" pointSize:28.0f];

You can explore this library for more features.

旧情别恋 2025-01-08 21:32:37

您检查字体名称是否正确,字体名称和文件名“Arial-Narrow.ttf”可能并不总是相同。要在 appDelegate.m 中执行此操作 -->应用程序 didFinishLaunchingWithOptions: 方法,编写以下代码,

NSLog("%@",[UIFont familyNames]);

这将是您安装的所有字体。另请记住,iOS 3.2 之后可以使用自定义字体

Did you check the font name correctly, the font name and file name "Arial-Narrow.ttf" might not be always same. To do this in appDelegate.m --> application didFinishLaunchingWithOptions: method, write the following code,

NSLog("%@",[UIFont familyNames]);

This will all fonts that you installed. And also remember custom fonts are available after IOS 3.2

挥剑断情 2025-01-08 21:32:37

如果你的字体名称中有两个单词,即“Century Gothic”(粗体),

你的代码应该如下所示

[UIFont fontWithName:@"CenturyGothic-Bold" size:14];

if your font has two words in its name, ie “Century Gothic”(bold),

your code should look like this

[UIFont fontWithName:@"CenturyGothic-Bold" size:14];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文