如何在iOS中以编程方式使用自定义字体(例如:Helvetica CY.ttf) [英] How to use custom font in iOS ( Eg: Helvetica CY.ttf ) with Xcode programatically

查看:148
本文介绍了如何在iOS中以编程方式使用自定义字体(例如:Helvetica CY.ttf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我想在我的应用程序中使用 Helvetica CY 字体。我已经配置为由苹果文档推荐。

  • 自定义字体显示在Storyboard的下拉列表中,但在我的类文件中不能以编程方式使用相同字体
  • 我已经记录了可用于应用程序的所有字体系列,但是 Helvetica CY 不会打印在控制台日志中。


  • 任何帮助将不胜感激。



    谢谢!

    解决方案

    它的简单而已。它也在xcode6.1中为我工作。



    尝试使用步骤:



    第1步:在XCode项目中包含字体 p>

    步骤2:确保它们包含在目标中

    第3步:仔细检查您的字体是否包含在资源中



    第4步:包含您的iOS自定义字体在您的应用程序plist



    第5步:找到字体的名称

    <$ p $ {
    $ {
    NSLog(@%@,family); $ p $ {code> for(NSString * family in [UIFont familyNames])
    $ b $(NSString * name in [UIFont fontNamesForFamilyName:family])
    {
    NSLog(@%@,name);





    $ b

    第6步:使用UIFont并指定字体的名称

      label.font = [UIFont fontWithName:@Helvetica CYsize:20]; 


    • I am trying to use Helvetica CY font in my app. I have configured it as recommended by apple docs.
    • The custom font shows up in dropdown in Storyboard, but unable to use the same font programatically in my class file.
    • I have logged all font families available for the app, but "Helvetica CY" is not printed on console log.

    Any help will be appreciated.

    Thanks!

    解决方案

    Its simple only. Its working for me in xcode6.1 too.

    Try using this steps :

    Step 1: Include your fonts in your XCode project

    Step 2: Make sure that they’re included in the target

    Step 3: Double check that your fonts are included as Resources in your bundle

    Step 4: Include your iOS custom fonts in your application plist

    Step 5: Find the name of the font

    for (NSString* family in [UIFont familyNames])
    {
        NSLog(@"%@", family);
    
        for (NSString* name in [UIFont fontNamesForFamilyName: family])
        {
            NSLog(@"  %@", name);
        }
    }
    

    Step 6: Use UIFont and specify the name of the font

    label.font = [UIFont fontWithName:@"Helvetica CY" size:20];
    

    这篇关于如何在iOS中以编程方式使用自定义字体(例如:Helvetica CY.ttf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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