Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on how to use FontAwesome pro Icon #232

Open
imrabti opened this issue Oct 1, 2019 · 15 comments
Open

Documentation on how to use FontAwesome pro Icon #232

imrabti opened this issue Oct 1, 2019 · 15 comments

Comments

@imrabti
Copy link

imrabti commented Oct 1, 2019

Would it be possible to offer an example of how to use this library with FontAwesome pro icons

@pgrundner
Copy link

pgrundner commented Dec 6, 2019

So far, here are some steps that made me get a little further

1.) add the pro *.otf files to your project.

2.) add the following list of font files to your info.plist file as Key UIAppFonts:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>Font Awesome 5 Brands-Regular-400.otf</string>
	<string>Font Awesome 5 Duotone-Solid-900.otf</string>
	<string>Font Awesome 5 Pro-Light-300.otf</string>
	<string>Font Awesome 5 Pro-Regular-400.otf</string>
	<string>Font Awesome 5 Pro-Solid-900.otf</string>
</array>
</plist>

3.) in your code, before using FontAwesome.swift the first time, call:
FontAwesomeConfig.usesProFonts = true

Thats it. Try to get the icon "fa-camera" with regular style, which is located in the pro version. Looks fine on my side.

I did not succeed to get all icons to work. E.g. fa-abacus is not showing up. Am I missing something in here?

@vjoomens
Copy link

Hi all, got pro fonts working, except... lots of icons are missing in the Enum (eg repeat). Seems this file is auto generated. Trying to regenerate didn't work: error. Please help. Is there a way to regenerate this file on xcode build?

@vjoomens
Copy link

I figured it out: remove the path: String line in the codegen.swift file (line 20) and it works. Simply use the newly generated FontAwesome enum in your project.

@mralexhay
Copy link

mralexhay commented Mar 14, 2020

@vjoomens Hi! I'm stuck on the same problem you had. How are you running the codegen file to regenerate the enum? The file isn't there when installing as a pod. Thanks!

@vjoomens
Copy link

@mralexhay check my fork of this project (https://github.com/vjoomens/FontAwesome.swift). It's fully compatible with FA pro.

@mralexhay
Copy link

@vjoomens amazing, this worked for me, thanks.

The only problem I haven't been able to sort is that using the Duotone style throws an error (despite the OTF being stored next to the others and being listed in the Info plist)

CleanShot 2020-03-15 at 12 35 57@2x

but the rest work perfectly.

@ghowen
Copy link

ghowen commented Mar 27, 2020

To implement FA Pro support, follow the instructions from @pgrundner.

To get all FA Pro icons, you need to hack a bit by following this: #230 (comment).

@austintt
Copy link

austintt commented Apr 3, 2020

Alright, I've followed the steps listed here and here, but I guess I've done something wrong.

UIFont(name: style.fontName(), size: fontSize)! on line 98 of FontAwesome unexpectedly finds nil for file.

Maybe you guys can help me catch my mistake.

I've added the Pro otf files to the project. The otf files are added to the app target. I've set FontAwesomeConfig.usesProFonts = true. I generated the new enum.swift following the instructions mentioned in the link above.

I added the following to my info.plist under the Fonts provided by application key:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>Font Awesome 5 Brands-Regular-400.otf</string>
	<string>Font Awesome 5 Pro-Light-300.otf</string>
	<string>Font Awesome 5 Pro-Regular-400.otf</string>
	<string>Font Awesome 5 Pro-Solid-900.otf</string>
</array>
</plist>

It seems like the file path for my new files is incorrect. Any ideas?

@ghowen
Copy link

ghowen commented Apr 4, 2020

@austintt It would help troubleshooting if you can catch the value of style.fontName() in the debugger. Then we would know which fontName is causing the problems.

A potential cause for your crash could be that even though duotone rendering is not support, you might have to add all the font file nevertheless:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>Font Awesome 5 Brands-Regular-400.otf</string>
	<string>Font Awesome 5 Duotone-Solid-900.otf</string>
	<string>Font Awesome 5 Pro-Light-300.otf</string>
	<string>Font Awesome 5 Pro-Regular-400.otf</string>
	<string>Font Awesome 5 Pro-Solid-900.otf</string>
</array>
</plist>

@austintt
Copy link

austintt commented Apr 5, 2020

@ghowen, thanks for the suggestion! I moved some stuff around and got a little more detail with the following error from loadFont: com.apple.CoreText.CTFontManagerErrorDomain error 105 - Could not register the font file(s). I tried referencing the duotone font in the plist, but found the same error.

This happens with the first call in my app to FontAwesome, requesting a light styled icon. Placing a breakpoint in loadFontAwesome(ofStyle), I see that the style.fontName returns FontAwesome5Pro-Light. I've tried it with the other styles, and the result is the same.

Here's the full error:

Could not register the font file(s), CTFontManagerErrorFontURLs=(
    "file:///Users/austin/Library/Developer/CoreSimulator/Devices/70E245F8-D1F1-4DCD-8779-A0C8A2F9ACE2/data/Containers/Bundle/Application/9738EF3B-EC31-4401-A88C-BD15A49F3BB3/TaskMinder.app/Font%20Awesome%205%20Pro-Light-300.otf"

@ghowen
Copy link

ghowen commented Apr 6, 2020

@austintt When you added the font files to the project, did you check the "Copy if needed" option? Also make sure that the all font files have the correct target membership. You can check this in the File Inspector when you click on the font files in your project. My current guess is that in your case the font files do not have a target membership.

@mralexhay
Copy link

@ghowen Did you ever find a solution to that unexpected nil error? Mine has started doing it and I haven't been able to find the answer yet. Thanks.

@ghowen
Copy link

ghowen commented Apr 17, 2020

@mralexhay You should probably check with @austintt if #232 (comment) did the trick for him. My bet is still that the fonts were not added to the target of the app.

@MatrixSenpai
Copy link
Collaborator

My personal recommendation, and how I prefer to do it, is to use the FontBlaster library instead. Make sure the first line in application(didFinishLaunching: with options:) is FontBlaster.blast()

Also ensure that all of the fonts appear in Xcode, and you have added them to the Copy Bundled Resources build phase, found by going to your target -> Build Phases

@austintt
Copy link

austintt commented Apr 18, 2020

@ghowen no dice, I had checked to make sure everything was a part of the correct target and copied to the app, everything was as good. For now, I'm just using the free fonts while I focus on other parts of my project. I'll try adding the Pro fonts again later. Thank you for the help though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants