ios - 在整个应用程序中将默认字体更改为自定义字体

标签 ios objective-c iphone swift fonts

我想在 iOS 应用程序中保留自定义字体。目前,我使用的是 iOS 默认字体。 有什么可能的方法吗?

如何包含自定义字体以便我可以使用它?

最佳答案

创建类别:

#import "UILabel+Helper.h"

@implementation UILabel (Helper)
- (void)setSubstituteFontName:(NSString *)name UI_APPEARANCE_SELECTOR {
     self.font = [UIFont fontWithName:name size:self.font.pointSize]; } 
@end

然后在 AppDelegate.m 中:

[[UILabel appearance] setSubstituteFontName:@"SourceSansPro-Regular"];

即使在 UIButtonUILabelUITableViewCellUICollectionViewCellUIViewUIContainerView 或应用程序中的任何位置,无需更改字体磅值。

这是一种节省内存的方法,而不是在您的 UIViewController 中枚举所有 View 。

关于ios - 在整个应用程序中将默认字体更改为自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27730658/

相关文章:

iOS:dyld:库未加载 SQLite

ios - Swift 等效于静态 Objective-C 表达式

iphone - 从网络请求中查找 iphone 设备 ID

ios - CLBeaconRegion initWithProximityUUID 返回 nil

ios - 在 iOS 中安排一个 ersatz 后台获取

ios - Crashlytics 没有给出正确的崩溃报告

ios - Objective-c Shinobi 网格更新到 2.8

objective-c - 为沙盒 Cocoa 应用程序创建临时文件

iphone - 在突出显示时更改 UIButton 边框颜色

iphone - 这是为 iPhone 游戏制作游戏循环的好方法吗?