Read this one first to get the background - http://www.johankarlsson.net/2015/09/fontawesome-using-xamarin-forms-and.html
I also moved the source to github since I might be adding stuff to it as I go along. Find it under johankson/awesome.
Here we go!
Download the font
Download the FontAwesome font and drop it in your Resource folder for the iOS project. Remember to change the "Copy to output directory" to "Always", otherwise you'll get a null reference exception.Edit the info.plist file
In the root of your iOS project you'll find a file called info.plist. We need to add stuff to it by editing the file using a text editor. If you simply double click it then Xamarin Studio (or Visual Studio) will open a GUI for it. We don't want that. I recommend Sublime Text for all you text editing needs.
Add a key named UIAppFonts followed by an array. One entry in the array should point to the font, in this case the fontawesome.ttf. If you have multiple fonts just add more entries. Make sure you add the complete path if you add the font to a folder.
Edit the XAML
Add a FontFamily attribute to what ever control you'd like display an icon through. The FontFamily attribute will be ignored on Android so you still need the custom renderer covered in the last blog post. The XAML is from the file MyPage.Xaml in the Forms project.
The result
As expected, we see some FontAwesome icons.
Extras
Remember that you can adjust the size and color by using the FontSize and TextColor properties. You can also add icons to buttons.
<Button Text="" FontSize="40" FontFamily="FontAwesome" />
Summary
So you see that iOS is simpler than Android when it comes to using custom fonts. I also know at the time of writing I haven't created a Windows Phone solution yet. I will as soon as time permits.
No comments:
Post a Comment