Wenfengcheng / xamarin-notes

xamarin journal
MIT License
3 stars 0 forks source link

Icons with Font Awesome 5 in Xamarin Forms #14

Open Wenfengcheng opened 5 years ago

Wenfengcheng commented 5 years ago

Stop the bitmap apocalypse!

Use custom fonts (such as FontAwesome) to create resizable, recolorable icons throughout your app 🤘

You should do this because:

Less image resources == smaller appsize Fonts are rendered vectors! Resize it by changing the font size! Recolour it by changing the font color! No more image density wrangling 💩 for Android.

<Label Text="&#xf00c;" 
           FontSize="50"
           TextColor="SkyBlue"
           VerticalOptions="Center" 
           HorizontalOptions="Center" >
        <Label.FontFamily>
            <OnPlatform 
 x:TypeArguments="x:String"
 Android="Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free Regular" 
 iOS="Font Awesome 5 Free" 
 WinPhone="Assets/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free" />
        </Label.FontFamily>
    </Label>

As shown above, you can even specify the icon’s size and color using FontSize and TextColor >Properties.

https://www.wintellect.com/using-fontawesome5-xamarin-forms/ https://github.com/matthewrdev/fa2cs