GithubHelp home page GithubHelp logo

gp-swift-font-awesome's Introduction

License

Copyright (c) 2019-2021, Matt Maddux. MIT License

Copyright (c) 2022-2023, Greg PFISTER. MIT License

Font Awesome 5 and 6 in SwiftUI Apps

This project is a fork of FASwiftUI by Matt Maddux. But it is intended to go its own way.

Easily integrate Font Awesome into your SwiftUI projects. Use Font Awesome icons as text in your SwiftUI views.

It supports Font Awesome 5 (Pro or Free) and Font Awesome 6 (Pro or Free).

(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/gpfister/gp-swift-font-awesome.git
  2. Download Font Awesome 5 or 6
    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:
    • For Font Awesome 5:
      • 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)
    • For Font Awesome 6:
      • icons.json
      • Font Awesome 6 Brands-Regular-400.otf
      • Font Awesome 6 [Free/Pro]-Regular-400.otf
      • Font Awesome 6 [Free/Pro]-Solid-900.otf
      • Font Awesome 6 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 GPFontAwesome
  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 (replace GPFontAwesome5 by GPFontAwesome6 to use Font Awesome 6):

import SwiftUI
import GPFontAwesome5

struct ContentView: View {
    var body: some View {
        GPFAText(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 GPFontAwesome5

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

Regualr Icon Screenshot

Set the color as you would any text.

import SwiftUI
import GPFontAwesome5

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

Regualr Icon Screenshot

Contributions


Contributions are welcome, please refer to these contributions guidelines.

License


Provided under the MIT License.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gp-swift-font-awesome's People

Contributors

gpfister avatar mattmaddux avatar zalarudo avatar

Stargazers

 avatar

Forkers

savyobrenner

gp-swift-font-awesome's Issues

Feature: Use another naming for the icon.json file

Is your feature request related to a problem? Please describe.

The icon.json file, required to get the link between the name and icon, may be duplicated with other resources on the bundle.

Describe the solution you'd like

It would be better to name the file font-awesome.json

Describe alternatives you've considered

Renaming the file and using a script at build time to perform the renaming

Additional context

N/A

Sharp font are not working

Describe the bug

Sharp is not supported as a regular (pro or free) font. There are two issues:

  • Using style = .sharp returns the brands fonts (bug)
  • Sharp now support Solid, Regular and Light

To Reproduce

Not required

Expected behavior

It should be possible to enforce a collection in combination with a style (which can be defaulted to regular when not provided). The GPFAText init method should include a collection parameter to select between brands, sharp, pro / free (pro should be used if available, free otherwise).

Screenshots

Not required

Desktop (please complete the following information):

Not required

Smartphone (please complete the following information):

Not required

Additional context

Font Awesome 6.4.0 is the latest release at the time of creating this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.