FontBlaster 5.3.0

FontBlaster 5.3.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布日期最后发布日期2022年5月
SPM支持 SPM

Maintained by Arthur Ariel Sabintsev.



  • By
  • Arthur Ariel Sabintsev

FontBlaster

将自定义字体按编程方式加载到 iOS、macOS 和 tvOS 应用中。

Swift Support Platform CocoaPods SwiftPM Compatible


关于

告别使用属性列表导入自定义字体,因为 FontBlaster 可以通过一行代码自动导入并加载应用中所有打包内的字体。

特性

  • CocoaPods 支持
  • Swift PM 支持
  • 自动从 Bundle.main 导入字体
  • 能够从远程打包导入字体
  • 示例项目

安装说明

Swift版本 分支名称 是否将继续接收更新?
5.1+ master
5.0 swift5.0
4.2 swift4.2
4.1 swift4.1
3.2 swift3.2
3.1 swift3.1

CocoaPods

pod 'FontBlaster' # Swift 5.1+
pod 'FontBlaster', :git => 'https://github.com/ArtSabintsev/FontBlaster.git', :branch => 'swift5.0' # Swift 5.0
pod 'FontBlaster', :git => 'https://github.com/ArtSabintsev/FontBlaster.git', :branch => 'swift4.2' # Swift 4.2
pod 'FontBlaster', :git => 'https://github.com/ArtSabintsev/FontBlaster.git', :branch => 'swift4.1' # Swift 4.1
pod 'FontBlaster', :git => 'https://github.com/ArtSabintsev/FontBlaster.git', :branch => 'swift3.2' # Swift 3.2
pod 'FontBlaster', :git => 'https://github.com/ArtSabintsev/FontBlaster.git', :branch => 'swift3.2' # Swift 3.1

Swift包管理器

.Package(url: "https://github.com/ArtSabintsev/FontBlaster.git", majorVersion: 4)

手动

  1. 下载FontBlaster.
  2. FontBlaster.swift复制到您的项目中。

设置

通常,所有字体都可以在Bundle.main中自动找到。即使您有一个自定义束包,它通常也位于mainBundle内部。因此,为了加载应用程序中的所有字体,无论其在哪个束包中,只需调用

FontBlaster.blast() // Defaults to Bundle.main if no arguments are passed

如果您从不在您的应用程序mainBundle内部的束包中加载,只需在blast(_:)方法中传递您的Bundle引用。

FontBlaster.blast(bundle:) // Takes one argument of type Bundle, or as mentioned above, defaults to Bundle.main if no arguments are passed

如果您需要加载的字体列表,重载的blast(_:)方法有一个返回该列表的完成处理程序。就像原始方法一样,此方法可以接受自定义的Bundle,或者在未传递任何参数时默认为Bundle.main

// Defaults to Bundle.main as no argument is passed
FontBlaster.blast() { (fonts) in
  print(fonts) // fonts is an array of Strings containing font names
}

// Custom bundle is passed as argument
FontBlaster.blast(bundle:) { (fonts) in
  print(fonts) // fonts is an array of Strings containing font names
}

要开启控制台调试语句,只需在调用任何一个blast()方法之前设置debugEnabled() = true

FontBlaster.debugEnabled = true
FontBlaster.blast()

示例项目

仓库中包含了一个示例iOS项目。当你启动应用时,所有字体都配置为加载自定义字体,但直到你点击导航栏上的按钮,它们才会 实际显示。点击按钮后,FontBlaster 会导入您的字体并重绘视图。

灵感

该项目基于一位Marco Arment他的博客上提出的旧解决方案。

创建和维护者

Arthur Ariel Sabintsev