快速为整个 iOS 应用程序使用自定义字体 [英] Using custom font for entire iOS app swift

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

问题描述

我知道要在屏幕上设置元素的自定义字体,我可以简单地执行someLabel.font=UIFont(name: "Exo 2.0", size: 15).

I know that to set a custom font of an element on the screen I can simply dosomeLabel.font=UIFont(name: "Exo 2.0", size: 15).

我想知道如何使用 swift 为整个应用程序设置它.(黑客将是对应用程序的每个元素都做我知道的事情,但这只会是可维护性的噩梦)

I was wondering how one could set it for an entire app using swift. (A hack would be to do what I know for every single element of the app but that is just going to be a maintainability nightmare)

我看到这个问题已经用objective-C标签问过了,如何在不指定大小的情况下为整个 iOS 应用程序设置自定义字体 但我对 Objective-C 不够熟悉,无法将代码移植到 swift >

I see that this question has already been asked with an objective-C tag, How to set a custom font for entire iOS app without specifying size but I'm not familiar enough with objective-C enough to port the code to swift

推荐答案

可以设置UILabel和其他UIViews的外观:

You can set the appearance of the UILabel and other UIViews:

UILabel.appearance().font = UIFont(name: "yourFont", size: yourSize)

更一般:

AnyUIView.appearance().font = UIFont(name: "yourFont", size: yourSize)

这篇关于快速为整个 iOS 应用程序使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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