I am using a Text which I want use SwiftUI custom fonts that can be offered as custom font from Apple, but I do not know, how can I see those offers? I also tried in canvas, and I just could do some padding or Color change, I am trying to see the List of Fonts that SwiftUI offer to us as custom one.
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.font(Font.custom("?", size: 20)) // <<: How can I know, what I can choose?
}
}
Update:
import SwiftUI
let customFonts: (allKinds: [String], allFonts: [String]) = allCustomFontsFinder()
func allCustomFontsFinder() -> (allKinds: [String], allFonts: [String]) {
let allKinds: [String] = UIFont.familyNames.sorted()
var allFonts: [String] = [String]()
allKinds.forEach { familyItem in
UIFont.fontNames(forFamilyName: familyItem).forEach { item in allFonts.append(item) }
}
return (allKinds: allKinds, allFonts: allFonts)
}
struct ContentView: View {
var body: some View {
List {
ForEach(customFonts.allFonts, id: \.self) { item in
HStack {
Text(item)
.font(Font.custom(item, size: 20))
.onTapGesture { print(item) }
Spacer()
Button(action: { let pasteboard = UIPasteboard.general; pasteboard.string = item }, label: {
Image(systemName: "doc.on.doc")
})
}
}
}
.padding()
.onAppear() {
print("count Of CustomFontKinds:", customFonts.allKinds.count)
print("count Of AllCustomFonts:", customFonts.allFonts.count)
}
}
}