Skip to content
项目

关于

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

设计与媒体

这些数字如何统计

可以做什么

  • Swift Package Manager Support
  • Automatically imports fonts from Bundle.main
  • Able to import fonts from remote bundles
  • Scans subdirectories and nested bundles recursively

实测星标增长

24小时
0
7天
-1
15天
-1
1个月
-1

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

FontBlaster

Programmatically load custom fonts into your iOS, macOS, and tvOS app.

Swift Support Platform SwiftPM Compatible


About

Say goodbye to importing custom fonts via property lists as FontBlaster automatically imports and loads all fonts in your app's Bundles with one line of code.

Features

  • Swift Package Manager Support
  • Automatically imports fonts from Bundle.main
  • Able to import fonts from remote bundles
  • Scans subdirectories and nested bundles recursively
  • Supports .ttf, .otf, and .ttc font files
  • Sample Project

Requirements

  • iOS 17.0+ / tvOS 17.0+ / macOS 14.0+
  • Swift 5.9+

Installation Instructions

Swift Package Manager

.package(url: "https://github.com/ArtSabintsev/FontBlaster.git", from: "6.0.0")

Manual

  1. Download FontBlaster.
  2. Copy FontBlaster.swift into your project.

Setup

Typically, all fonts are automatically found in Bundle.main. Even if you have a custom bundle, it's usually lodged inside of the mainBundle. Therefore, to load all the fonts in your application, irrespective of the bundle it's in, simply call:

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

If you are loading from a bundle that isn't found inside your app's mainBundle, simply pass a reference to your Bundle in the blast(bundle:) method:

FontBlaster.blast(bundle: myCustomBundle)

If you need a list of all of the loaded fonts, an overloaded version of the blast(bundle:) method has a completion handler that returns just that. Just like the original method, this method takes either a custom Bundle or defaults to Bundle.main if no argument is passed.


// 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: myCustomBundle) { fonts in
  print(fonts) // fonts is an array of Strings containing font names
}

Registered fonts are file-backed, so don't move or delete a font file after it has been loaded.

To turn on console debug statements, simply set debugEnabled to true before calling either blast() method:

FontBlaster.debugEnabled = true
FontBlaster.blast()

Sample Project

A Sample iOS project is included in the repo. When you launch the app, all fonts are configured to load custom fonts, but don't actually display them until you push the button on the navigation bar. After pushing the button, FontBlaster imports your fonts and redraws the view.

Inspiration

This project builds upon an old solution that Marco Arment proposed and wrote about on his blog.

Created and maintained by

Arthur Ariel Sabintsev

探索相关项目

加载中…