Last active
November 11, 2023 19:52
-
-
Save lucianoschillagi/c3ab96b0d36c147691481a94ac52433e to your computer and use it in GitHub Desktop.
Apple Fonts Slider Catalogue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct FontSliderCatalogue: View { | |
| @State private var selectedFontIndex: Int = 0 | |
| private var allFontNames: [String] { | |
| return UIFont.familyNames.flatMap { UIFont.fontNames(forFamilyName: $0) } | |
| } | |
| var body: some View { | |
| ZStack { | |
| Color.black.ignoresSafeArea() | |
| VStack { | |
| Spacer() | |
| Text("A") | |
| .font(Font.custom(allFontNames[selectedFontIndex], size: 290)) | |
| .frame(height: 450) | |
| .padding() | |
| Text(allFontNames[selectedFontIndex]).font(.title2).bold() | |
| Spacer() | |
| Slider(value: Binding( | |
| get: { Double(Int(self.selectedFontIndex)) }, | |
| set: { self.selectedFontIndex = Int($0) } | |
| ), in: 0...(Double(allFontNames.count) - 1), step: 1) | |
| .padding() | |
| } | |
| .foregroundColor(.white) | |
| .padding() | |
| } | |
| } | |
| } | |
| #Preview { | |
| FontSliderCatalogue() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment