{"id":17068955,"url":"https://github.com/kgn/kgnpreferredfontmanager","last_synced_at":"2025-04-12T19:10:07.098Z","repository":{"id":18575065,"uuid":"21777973","full_name":"kgn/KGNPreferredFontManager","owner":"kgn","description":"Helper class to registering custom fonts for UIFontTextStyle","archived":false,"fork":false,"pushed_at":"2020-02-20T06:43:19.000Z","size":121,"stargazers_count":21,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T19:10:00.351Z","etag":null,"topics":["font","ios","swift","ui","uikit"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-12T22:34:54.000Z","updated_at":"2024-05-30T08:31:26.000Z","dependencies_parsed_at":"2022-08-21T03:50:44.353Z","dependency_job_id":null,"html_url":"https://github.com/kgn/KGNPreferredFontManager","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgn%2FKGNPreferredFontManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgn%2FKGNPreferredFontManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgn%2FKGNPreferredFontManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgn%2FKGNPreferredFontManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgn","download_url":"https://codeload.github.com/kgn/KGNPreferredFontManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618277,"owners_count":21134200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["font","ios","swift","ui","uikit"],"created_at":"2024-10-14T11:15:42.411Z","updated_at":"2025-04-12T19:10:07.077Z","avatar_url":"https://github.com/kgn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KGNPreferredFontManager\n\nHelper class to registering custom fonts for `UIFontTextStyle`. \n\n[![Swift 3](http://img.shields.io/badge/Swift-3-orange.svg)]()\n[![Release](https://img.shields.io/github/release/kgn/KGNPreferredFontManager.svg)](/releases)\n[![License](http://img.shields.io/badge/License-MIT-lightgrey.svg)](/LICENSE)\n\n[![Build Status](https://travis-ci.org/kgn/KGNPreferredFontManager.svg)](https://travis-ci.org/kgn/KGNPreferredFontManager)\n[![Test Coverage](http://img.shields.io/badge/Tests-79%25-yellow.svg)]()\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-Compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/KGNPreferredFontManager.svg)](https://cocoapods.org/pods/KGNPreferredFontManager)\n[![CocoaPods Platforms](https://img.shields.io/cocoapods/p/KGNPreferredFontManager.svg)](https://cocoapods.org/pods/KGNPreferredFontManager)\n\n[![Twitter](https://img.shields.io/badge/Twitter-@iamkgn-55ACEE.svg)](http://twitter.com/iamkgn)\n[![Star](https://img.shields.io/github/followers/kgn.svg?style=social\u0026label=Follow%20%40kgn)](https://github.com/kgn)\n[![Star](https://img.shields.io/github/stars/kgn/KGNPreferredFontManager.svg?style=social\u0026label=Star)](https://github.com/kgn/KGNPreferredFontManager)\n\n`iOS 7` introduced the concept of dynamic fonts for accessibility and readability. This library makes it easy to implement these features to help make your app more accessible and readable.\n\nThis library also helps keep the fonts in your app consistent by setting a strict set of fonts to use based on the text styles introduced in `iOS 7`.\n\nSubclasses of `UILabel` and `UIButton` are also provided that work with these text styles and the `KGNPreferredFontManager` to automatically update and resize to the appropriate font size for the user’s text size and accessibility settings. It is recommended that [KGNAutoLayout](https://github.com/kgn/KGNAutoLayout) be used in conjunction with this library so that elements resize and adjust appropriately as font sizes change.\n\n[![Example Gif](https://d13yacurqjgara.cloudfront.net/users/7253/screenshots/1877784/fonts.gif)](https://dribbble.com/shots/1877784-Dynamic-Fonts)\n\n## Installing\n\n### Carthage\n```\ngithub \"kgn/KGNPreferredFontManager\"\n```\n\n### CocoaPods\n```\npod 'KGNPreferredFontManager'\n```\n\n## Examples\n\n### PreferredFontManager\nCreate a `PreferredFontManager` to specify the font sizes to be used when the user changes their accessibility settings. \n\nThe following code registers each of the standard text styles with a `fontWeight` and `baseFontSize`. This base font size is used for the `UIContentSizeCategoryLarge` font size and then incremented and decremented by the amounts passed to the `increment` and `decrement` properties. \n\nThere is an additional property that defines if the incrementing should extend into the extra accessibility size categories. This `includeAccessibilitySizes` argument is `false` by default, but is often useful to make sure body text is extra large, like in `Messages.app`.\n\nThere are two versions of this method. One takes `fontWeight: CGFloat`, which is a `UIFontWeight...` constant introduced in `iOS 8.2`. The other takes `fontName: String` which is a the name of the font, either a system one or a custom one.\n\n#### fontWeight(iOS 8.2+)\nCheck out the Example app provided to see this in action.\n\n``` Swift\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .headline, fontWeight: UIFontWeightUltraLight, baseFontSize: UIFont.systemFontSize*4, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .subheadline, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.systemFontSize*2, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .body, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.labelFontSize, increment: 2, decrement: 1, includeAccessibilitySizes: true)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .caption1, fontWeight: UIFontWeightMedium, baseFontSize: UIFont.systemFontSize, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .caption2, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.systemFontSize, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .footnote, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.smallSystemFontSize, increment: 1, decrement: 1)\n```\n\n#### fontName\n\n``` Swift\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .headline, fontName: \"AvenirNext-Light\", baseFontSize: 28, increment: 2, decrement: 2)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .subheadline, fontName: \"AvenirNext-Regular\", baseFontSize: 22, increment: 2, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .body, fontName: \"AvenirNext-Regular\", baseFontSize: 17, increment: 1, decrement: 1, includeAccessibilitySizes: true)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .caption1, fontName: \"AvenirNext-Medium\", baseFontSize: 15, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .caption2, fontName: \"AvenirNext-Regular\", baseFontSize: 13, increment: 1, decrement: 1)\nPreferredFontManager.sharedManager.registerFonts(forTextStyle: .footnote, fontName: \"AvenirNext-Regular\", baseFontSize: 11, increment: 1, decrement: 1)\n```\n\n### PreferredFontButton, PreferredFontLabel \u0026 PreferredFontTextField\n`PreferredFontButton`, `PreferredFontLabel` and `PreferredFontTextField` are subclasses of `UIButton`, `UILabel` and `UITextField`respectively but they incorporate a `PreferredFontManager` and subscribe to `UIContentSizeCategoryDidChangeNotification` so the font used it automatically updated for the selected accessibility font size selected buy the user.\n\n``` Swift\nlet label = PreferredFontLabel()\nlet button = PreferredFontButton()\nlet textField = PreferredFontTextField()\n```\n\n#### Property: textStyle\nBy default the `UIFontTextStyle.body` is used, but this can be customized and changed at any time with the `textStyle:` initializer or the `.textStyle` property.\n\n``` Swift\nlet label = PreferredFontLabel(textStyle: .headline)\nlet button = PreferredFontButton(textStyle: .headline)\nlet textField = PreferredFontTextField(textStyle: .headline)\n```\n\n#### Property: preferredFontManager\nBy default this property is set to `PreferredFontManager.shared`, if there is not a registered text style `UIFont.preferredFontForTextStyle` is used instead. This property can also be set to a custom `PreferredFontManager` object.\n\n## Progress:\n- [X] Tests\n- [X] Travis\n- [X] Badges\n- [X] Carthage\n- [X] CocoaPods\n- [X] Description\n- [X] Documentation\n- [ ] AppleTV\n- [X] Prebuilt Frameworks\n- [ ] Travis Test Matrix\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgn%2Fkgnpreferredfontmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgn%2Fkgnpreferredfontmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgn%2Fkgnpreferredfontmanager/lists"}