https://github.com/yonat/systemfontoverride
Easy font branding for your iOS app
https://github.com/yonat/systemfontoverride
Last synced: about 1 year ago
JSON representation
Easy font branding for your iOS app
- Host: GitHub
- URL: https://github.com/yonat/systemfontoverride
- Owner: yonat
- License: mit
- Created: 2024-07-19T09:25:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-25T10:03:22.000Z (almost 2 years ago)
- Last Synced: 2025-03-01T20:25:12.588Z (over 1 year ago)
- Language: Swift
- Size: 171 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# SystemFontOverride
Easy font branding for your iOS app.
[![Swift Version][swift-image]][swift-url]
[![License][license-image]][license-url]
[](https://img.shields.io/cocoapods/v/SystemFontOverride.svg)
[](http://cocoapods.org/pods/SystemFontOverride)
[](http://makeapullrequest.com)

## Features
* Override the default system font with your own branded font.
* Compatible with both UIKit and SwiftUI.
* Simple and intuitive API for quick integration.
## Usage
Instant font branding, automatically overriding system font:
```swift
UIFont.systemFontFamilyOverride = "Marker Felt" // replace with appropriate font
```
Explicitly specify font in UIKit:
```swift
someUIKitElement.font = .systemFontOverride(size: 16)
```
Explicitly specify font in SwiftUI:
```swift
someSwiftUIView
.font(.systemOverride(size: 16))
```
## Installation
### CocoaPods:
```ruby
pod 'SystemFontOverride'
```
### Swift Package Manager:
```swift
dependencies: [
.package(url: "https://github.com/yonat/SystemFontOverride", from: "1.0.0")
]
```
## Limitations
Most UI elements will just work with the override font.
However, a few elements completely ignore the override:
- Sheet presented by `ColorPicker` or `UIColorWell`
Additionally, some SwiftUI controls require explicit `.font()` modifier to update their title font:
- `Picker`
- `Menu`
- `Toggle`
- `bordered` and `borderedProminent` button styles
- `Label` in some contexts
See the Demo app for details.
## Mechanism
To automatically override the system font, SystemFontOverride uses [method swizzling](https://developer.apple.com/documentation/objectivec/1418769-method_exchangeimplementations) for `UIFont.systemFont(ofSize:)` and related methods.
Segmented controls and `UITextField` ignore the system font override, but their `appearance()` proxy correctly sets their titles to the override font.
[swift-image]:https://img.shields.io/badge/swift-5.0-orange.svg
[swift-url]: https://swift.org/
[license-image]: https://img.shields.io/badge/License-MIT-blue.svg
[license-url]: LICENSE.txt