iPad中的自定义字体不起作用

时间:2012-02-16 07:31:37

标签: iphone ios ios4 ios5

在我的应用程序中我使用自定义字体。我将我的font.ttf文件复制到我的项目目录中,并使用以下代码将自定义字体设置为标签。

[input setFont:[UIFont fontWithName: @"My Font" size: input.font.pointSize]]

问题是它在iPhone 4.2模拟器中运行完美,但在iPad 4.2模拟器中它只显示默认字体。如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

以下代码用于自定义字体。

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: @"Grinched" size:24]];
[label1 setText:@"Grinched Font"];
[[self view] addSubview:label1];

UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: @"Energon" size:18]];
[label2 setText:@"Energon Font"];
[[self view] addSubview:label2];

如果您想要显示该you visits the refrence link here

的教程

这段代码可能有助于开发。

快乐编码

谢谢和问候 @samuel

答案 1 :(得分:0)

如果您想使用自定义字体,请执行以下步骤...

  1. 将字体文件添加到资源文件
  2. 修改您的Info.plist:使用密钥Fonts provided by application添加新条目。
  3. 对于每个文件,将文件名添加到此数组
  4. 在下面的示例中,我添加了字体“DejaVu Sans Mono”:

    Info.plist: adding custom fonts

    在您的应用程序中,您可以使用

        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 240, 50)];
    
        [label1 setFont: [UIFont fontWithName: @"DejaVuSansMono-Bold" size:14.f]];
    

    或者如果你想在html / css中使用它,只需使用font-family:DejaVu Sans Mono;

    注意:这在iOS 3.2及更高版本中可用。

相关问题