如何在不指定大小的情况下为整个 iOS 应用程序设置自定义字体 [英] How to set a custom font for entire iOS app without specifying size

查看:22
本文介绍了如何在不指定大小的情况下为整个 iOS 应用程序设置自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 iOS 应用程序 中应用自定义字体.我发现我可以使用:

I'm trying to apply a custom font throughout my iOS app. I found that I could use:

 [[UILabel appearance] setFont:[UIFont fontWithName:@"Proxima Nova" size:17.0]];

  • 为所有UILabels 设置默认字体和大小.但是,并非我所有的 UILabels 都使用相同的字体大小.

    • To set the default font and size for all UILabels. However, not all my UILabels share the same font size.

      为整个 iOS 应用设置默认字体?,有人有同样的顾虑,被告知将size参数设置为0.0只设置字体而不设置字体大小.

      In Set a default font for whole iOS app?, someone had the same concern, and was told to set the size parameter to 0.0 to only set the font and not font size.

      关于如何通用设置字体而不是大小的任何建议?非常感谢!

      Any suggestions as to how I can universally set a font but not size? Thanks a lot!

      推荐答案

      - (void)viewDidLoad
      {
          [super viewDidLoad];
          [self setFontFamily:@"FagoOfficeSans-Regular" forView:self.view andSubViews:YES];
      }
      
      -(void)setFontFamily:(NSString*)fontFamily forView:(UIView*)view andSubViews:(BOOL)isSubViews
      {
          if ([view isKindOfClass:[UILabel class]])
          {
              UILabel *lbl = (UILabel *)view;
              [lbl setFont:[UIFont fontWithName:fontFamily size:[[lbl font] pointSize]]];
          }
      
          if (isSubViews)
          {
              for (UIView *sview in view.subviews)
              {
                  [self setFontFamily:fontFamily forView:sview andSubViews:YES];
              }
          }    
      }
      

      这篇关于如何在不指定大小的情况下为整个 iOS 应用程序设置自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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