Xoyce
Xoyce

Reputation: 367

Nativescript and FontAwesome

I am trying to use icon font FontAwesome in Nativescript application, which is possible according to this article https://www.nativescript.org/blog/mobile-app-best-practices---use-font-instead-of-image-to-show-an-icon

I did everything that is described in that article:

But result is rather disappointing:

Not working I also tried the "\uf230" syntax, but that renders as plain text.

What am I doing wrong?

Upvotes: 4

Views: 5606

Answers (2)

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

Could be a few things. Does it work on iOS? As your CSS definition is iOS compatible, not Android as Android needs the actual filename (without extension) whereas iOS needs the font name. So I have this to be xplatform-ready (the file is 'fontawesome-webfont.ttf'):

.fa {
  font-family: 'FontAwesome', fontawesome-webfont;
}

The \f005 syntax is OK (<Label class="fa" [text]="'\uf005'"></Label>), but I'm using the splendid nativescript-ngx-fonticon plugin (there's also a non-Angular one) to be able to do this instead:

<Label class="fa" [text]="'fa-shopping-basket' | fonticon"></Label>

Upvotes: 9

Delfino
Delfino

Reputation: 567

To make it work, you must make sure that the "fonts" directory is inside the "app" folder and that the following files exist:

font-awesome.eot
font-awesome.ttf

I opted to adopt this font as the default of my application, so I do not have to worry about where I'm going to use it and how much to enter the right class, everything is getting very good and the result is perfect.

In CSS, you only have to define a selector according to your interest for the source to be used, so just use the directive:

page {
  font-family: 'FontAwesome'
} 

Then where you want an icon, just use an html entity that represents it as it searches the site: http://fontawesome.io/icons/

See images: enter image description here

You can see this video where I was based to start. It corrects in the video the extension used to be attentive.

Upvotes: 1

Related Questions