Swiftpack.co -  mattmaddux/FASwiftUI as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
mattmaddux/FASwiftUI
Easy Font Awesome in SwiftUI
.package(url: "https://github.com/mattmaddux/FASwiftUI.git", from: "1.0.4")

FASwiftUI

Easily use FontAwesome in your SwiftUI projects. Supports Font Awesome 5 Pro or Free. Easily use Font Awesome icons as text in your SwiftUI views. Use an included picker view to search for and select icons.

(Does not currently support the Duotone style.)

Installation - Swift Package Manager


  1. Add the Swift package to your Xcode project
    1. File -> Swift Packages -> Add Package Dependency
    2. Enter https://github.com/mattmaddux/FASwiftUI.git
  2. Download Font Awesome
    1. Go to https://fontawesome.com/download
    2. Download the Pro or Free version
  3. Drag the following files from the download to your project:
    • icons.json
    • Font Awesome 5 Brands-Regular-400.otf
    • Font Awesome 5 [Free/Pro]-Regular-400.otf
    • Font Awesome 5 [Free/Pro]-Solid-900.otf
    • Font Awesome 5 Pro-Light-300.otf (Pro Only)
  4. Add files to target - For each of the files in the last step:
    1. Select the file in Project Navigator
    2. Open the Inspectors bar on the right and select the file inspector (first tab)
    3. Under Target Membership select each target you need to use FASwiftUI
  5. Add Fonts to Info.plist
    1. Open your project's info.plist
    2. Right-Click in a blank area and choose "Add Row"
    3. Name the new entry "Fonts provided by application"
    4. Expand the entry by clicking the triangle to the left
    5. Add a new entry for each of the "otf" files you added to your project, using the full filename including the extension
  6. You're done!

Usage


Use a Font Awesome icon in any view:

import SwiftUI
import FASwiftUI

struct ContentView: View {
    var body: some View {
        FAText(iconName: "bomb", size: 200)
    }
}

Regualr Icon Screenshot

You can also choose an alternate style. (This is ignored if the icon is a brand and currently duotone is not supported and will default back to regular.)

import SwiftUI
import FASwiftUI

struct ContentView: View {
    var body: some View {
        FAText(iconName: "bomb", size: 200, style: .solid)
    }
}

Regualr Icon Screenshot

Set the color as you would any text.

import SwiftUI
import FASwiftUI

struct ContentView: View {
    var body: some View {
        FAText(iconName: "bomb", size: 200)
            .foregroundColor(Color.red)
    }
}

Regualr Icon Screenshot

Have the user select an icon with an easy string binding (not available on macOS)

import SwiftUI
import FASwiftUI

struct ContentView: View {
    
    @State var selectedIcon: String?
    @State var showingPicker: Bool = false
    
    var body: some View {
        VStack {
            FAText(iconName: selectedIcon ?? "question-square", size: 200)
            Button(action: {
                self.showingPicker = true
            }) {
                Text("Choose icon")
            }
        }
        .sheet(isPresented: $showingPicker) {
            FAPicker(showing: self.$showingPicker, selected: self.$selectedIcon)
        }
    }
}

Regualr Icon Screenshot

Or perform a search manually for a dictionary of Icons

Dependencies (Auto Installed with Swift Package)


QGrid - https://github.com/Q-Mobile/QGrid

GitHub

link
Stars: 43
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

1.0.4
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API