There are two static methods on UIFont:
UIFont.fixSized(_ size: CGFloat, family: FontTextFamily)- creates fix sized font with required font size and font familyUIFont.dynamicallySized(for textStyle: FontTextStyle, family: FontTextFamily)- creates dynamically sized font for certain text style.
Parameters for FontTextStyle:
head(type)body(type)caption(type)
type represents the type of text you can choose from the following:
- extraSmall
- small
- medium
- large
Parameters for FontTextFamily: All the embedded font families, if you want it to support custom one, add case to FontTextFamily enumeration
Also you can use .bolded and .italicized on the font.
textLabel.font = .dynamicallySized(for: .head(.medium), family: .avenir).bolded
CocoaPods:
Add the line pod "DynamicFonts" to your Podfile
Manual:
Clone the repo and drag the file DynamicFonts.swift into your Xcode project.
- iOS 8 and above
DenisLitvin, den.litvinn@gmail.com
DynamicFonts is available under the MIT license. See the LICENSE file for more info.