How to Use Icon Fonts in Xamarin.Forms App | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (202)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (64)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (895)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (38)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (500)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (380)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (321)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
How to Use Icon Fonts

How to Use Icon Fonts in Xamarin.Forms App

In a mobile app, the visual representation of elements and actions is generally delivered through images. Images convey the meaning or action of an element without language. Images are the most common and friendly way of representation in mobile apps.

Nowadays, images play a vital role in Xamarin.Forms apps. An image can represent navigation, illustration, and usability of an element present in an app. Images should fit within the screen area and be clearly visible. We encounter some complications when rendering an image across a variety of mobile screens based on their size and screen density. For these scenarios, icon fonts are the best solution to overcome image complications in Xamarin.Forms apps iconography.

What is an Icon Font?

Icon Fonts are normal fonts that contain symbols and glyphs. These icons are vector icons, so they are very scalable and fit into any mobile device screen. You can add these icons like they’re normal text.

Why is it the best approach to use icon fonts instead of images?

Vector design: Vector icons are scalable, meaning you don’t need different images with different sizes and different resolutions based on the device. Icon font scaling can be handled through the FontSize property.

Lightweight: Generate hundreds of icons in a single font file that’s only a few KBs in size.

Color customization: Set icon color with the TextColor property. Dynamic colors are not possible with static images

Where can I get free Icon Fonts?

There are many icon font vendors on the market, but Syncfusion Metro Studio is a favorite for users because it packs thousands of beautiful, royalty-free icons that can be used in commercial applications. Its icons can also be used in open-source projects and hosted on sites like GitHub, BitBucket, and more.

Syncfusion Metro Studio

Syncfusion Metro Studio is a collection of over 7,000 flat and wireframe icon templates. You can create custom icon font packages from selected sets of icons, and also export the font package as a TTF file. This TTF file can be integrated into your Xamarin.Forms app.

Create Icon Fonts using Metro Studio
Create Icon Fonts using Metro Studio

How to integrate a font icon into a Xamarin.Forms application

Using Label: Traditionally, Label is used to display icon fonts in Xamarin.Forms apps. It respects all properties in a font just like normal text but loads symbols based on glyphs.

<Label Text="&#xe700 ;"
       FontSize="44"
       FontFamily="{OnPlatform iOS=MetroStudio, Android=MetroStudio.ttf#, UWP= MetroStudio.ttf#MetroStudio}"
       TextColor="Orange"/>
Icon loaded by Xamarin.Forms Label
Icon Loaded by Xamarin.Forms Label

Using Image: From Xamarin.Forms 3 onward, Image supports font icons by specifying the font icon data in a FontImageSource object.

<Image>
   <Image.Source>
       <FontImageSource Glyph="&#xe700 ;" 
                        Color="Orange" 
                        FontFamily="{OnPlatform iOS=MetroStudio, Android=MetroStudio.ttf#, UWP= MetroStudio.ttf#MetroStudio}" 
                        Size="44" />
   </Image.Source>
</Image>

Icon loaded by Xamarin.Forms Image
Icon Loaded by Xamarin.Forms Image

The following properties customize the appearance of an icon font inserted with Label or Image:

  • Glyph/Text: Unicode character value of the font icon, specified as a string.
  • Size/FontSize: A double value that indicates the size, in device-independent units, of the rendered font icon.
  • FontFamily: A string representing the font family to which the font icon belongs.

How to apply an icon font to a custom component

If you create your own custom component, you need to implement a label or image within it to use icon fonts. If you use Syncfusion Xamarin.Forms controls however, you can immediately plug in icon fonts and use them anywhere. Let’s look at using icon fonts with some of Syncfusion’s Xamarin.Forms controls.

Xamarin.Forms Tabbed View with font icons

The Tabbed View is a simple, intuitive interface for tab navigation in mobile applications. The Syncfusion Xamarin.Forms Tabbed View features font icon support, which can be used as shown in the following code:

<tabview:SfTabItem Title="Chat" 
                   TitleFontSize="14"
                   IconFont="&#xe700 ;" 
                   FontIconFontFamily="{StaticResource fonts}">
Xamarin.Forms Tabbed View with Font Icons
Xamarin.Forms Tabbed View with font icons

Xamarin.Forms Button with font icons

The Xamarin.Forms Button is a custom button control. You can add font icons to its content as follows:

 <button:SfButton Text="&#xe700 ;" 
                  FontFamily="{StaticResource fonts}" />
Xamarin.Forms Button with Font Icons
Xamarin.Forms Button with font icons

Xamarin.Forms Radial Menu with font icons

The Xamarin.Forms Radial Menu control provides a hierarchy of menu items in a circular layout. You can add a font icon to each radial menu item as follows:

<radialMenu:SfRadialMenuItem FontIconText="&#xe700 ;" 
                             IconFontFamily="{StaticResource fonts}" />
Xamarin.Forms Radial Menu with Font Icons
Xamarin.Forms Radial Menu with font icons

Xamarin Forms Segmented control with font icons

The Xamarin Segmented control is a linear segment made up of multiple segments. You can add font icons to each segment item as follows:

<segmented:SfSegmentItem Text="&#xe700 ;"
                   FontSize="14"
                   FontIconFontFamily="{StaticResource fonts}">
Xamarin.Forms Segmented Control with Font Icons
 Xamarin.Forms Segmented Control with font icons

Xamarin Forms Navigation Drawer with font icons

The Xamarin.Forms Navigation Drawer control is a sliding panel that can be used to hide content like menus from the visible area of the screen. Font icons can be added to each menu item as shown in the following figure:

Xamarin.Forms Navigation Drawer with font icons
 Xamarin.Forms Navigation Drawer with font icons

Xamarin.Forms Switch Control with  font icons

From Xamarin.Forms 3 onwards, Image supports font icons by specifying the font icon data in a FontImageSource object. Here, our Xamarin.Forms Switch control, which has ImageSource API, supports font icons.

Xamarin.Forms Switch with Font Icon
Xamarin.Forms Switch with the font icon
<syncfusion:DefaultSwitchSettings x:TypeArguments="syncfusion:OffState">
  <syncfusion:DefaultSwitchSettings.ThumbImageSource>
       <FontImageSource Glyph="&#xe700 ;"
                        Color="Orange"
                        FontFamily="{OnPlatform iOS=MetroStudio, Android=MetroStudio.ttf#, UWP= MetroStudio.ttf#MetroStudio}"
                        Size="44" />
  </syncfusion:DefaultSwitchSettings.ThumbImageSource>
</syncfusion:DefaultSwitchSettings>

Note: Similarly, all Syncfusion controls that expose ImageSource type API will support icon font.

Conclusion

In this blog post, we have walked through the benefits of icon fonts and how easy it is to import an icon font in Syncfusion Xamarin.Forms controls. We invite you to see all our Xamarin.Forms controls in action by downloading our free evaluation. You can also explore our samples available on Google Play and the Microsoft Store. Learn about the controls’ advanced features in our documentation.

If you have any questions or require clarifications about these controls, please let us know in the comments below. You can also contact us through our support forumsupport portal, or feedback portal. We are happy to assist you!

Recommended resources

Tags:

Share this post:

Comments (5)

[…] on September 2, 2019by admin submitted by /u/prabakarinfo [link] [comments] No comments […]

[…] How to use font icons in Xamarin.Forms app? (Selva Ganapathy Kathiresan) […]

Perhaps cover UWP?

Selva Ganapathy Kathiresan
Selva Ganapathy Kathiresan

Thanks for the Comment. We will cover UWP with the above code snippets

Do you know how I would use the iOS SFSymbols in xamarin forms?

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed