Skip to content

Instantly share code, notes, and snippets.

@lucianoschillagi
Last active November 11, 2023 19:52
Show Gist options
  • Save lucianoschillagi/c3ab96b0d36c147691481a94ac52433e to your computer and use it in GitHub Desktop.
Save lucianoschillagi/c3ab96b0d36c147691481a94ac52433e to your computer and use it in GitHub Desktop.
Apple Fonts Slider Catalogue
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