Built in Fonts list

Hi all,

In the Swift UI Specialist Course, Shapes and Text, How to Use Text and Their Modifiers, the picture below is shown as an interactive list that shows all the built in fonts (minute 6:45). Can anyone tell me where I can find this?

image

Looks to me like Mark found this somewhere.

Here is some code to create a list of the built in available fonts with the font name shown in that Font.

As for how you create the Alphabetical index I have no idea…yet

struct FontList: Identifiable {
    var id = UUID()
    var name: String
}

struct ContentView: View {
    @State private var fontArray = [FontList]()
    @State private var filtered = [FontList]()
    @State private var searchText = ""
    var body: some View {
        NavigationStack {
            List {
                ForEach(filtered) { fontName in
                    HStack {
                        Text(fontName.name)
                            .font(.custom(fontName.name, size: 25))
                            .padding(.bottom, 1)
                        Spacer()
                    }
                }
                .searchable(text: $searchText)
            }
            .listStyle(.plain)
            .navigationTitle("Built In Fonts")

        }
        .onAppear {
            createFontArray()
            filtered = fontArray
        }
        .onChange(of: searchText) { oldValue, newValue in
            if !searchText.isEmpty {
                filtered = fontArray.filter( {$0.name.lowercased().contains(searchText.lowercased())})
            } else {
                filtered = fontArray
            }
        }
    }

    func createFontArray() {
        fontArray = []
        let familyNames = UIFont.familyNames

        for family in familyNames {
            let fontNames = UIFont.fontNames(forFamilyName: family)

            for font in fontNames {
                fontArray.append(FontList(name: font))
            }
        }
    }
}

#Preview {
    ContentView()
}

Hi Chris,

This is super helpful. Once again, thanks a lot!

Have a great weekend!