Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasmusson authored Jan 30, 2020
1 parent 7c651a4 commit 9bc808e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion basics/DynamicFont/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,27 @@ You can style preferred fonts via their `UIFontDescriptor.SymbolicTraits`.
### How to bold

```swift

extension UIFont {
func withTraits(traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
let descriptor = fontDescriptor.withSymbolicTraits(traits)
return UIFont(descriptor: descriptor!, size: 0) //size 0 means keep the size as it is
}

func bold() -> UIFont {
return withTraits(traits: .traitBold)
}

func italic() -> UIFont {
return withTraits(traits: .traitItalic)
}
}

let boldFont = UIFont.preferredFont(forTextStyle: .footnote).withTraits(traits: [.traitBold])
percentOfDataLimitReachedLabel.font = boldFont
percentOfDataLimitReachedLabel.adjustsFontForContentSizeCategory = true
```

### Other Traits

```swift
Expand All @@ -119,5 +136,4 @@ public static var traitLooseLeading: UIFontDescriptor.SymbolicTraits { get }
### Links that help

- [Apple UIFontTextStyle](https://developer.apple.com/documentation/uikit/uifonttextstyle)
- [Example](https://kitefaster.com/2016/08/17/dynamic-type-in-ios-using-uifonttextstyle/)
- [Bold preferredFont](https://spin.atomicobject.com/2018/02/02/swift-scaled-font-bold-italic/)

0 comments on commit 9bc808e

Please sign in to comment.