Last active
March 2, 2016 13:00
-
-
Save dkudelko/75d1e9378f6428da5e20 to your computer and use it in GitHub Desktop.
Xamarin Forms Android Custom Font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Xamarin.Forms; | |
//https://developer.xamarin.com/guides/xamarin-forms/user-interface/text/fonts/ | |
[assembly: ExportRenderer(typeof(Label), typeof(CustomFontLabelRenderer))] | |
namespace dkudelko.Mobile.Android | |
{ | |
public class CustomFontLabelRenderer : LabelRenderer | |
{ | |
private static readonly string[] CustomFontFamily = new [] { "FontAwesome" }; | |
private static readonly Tuple<FontAttributes, string>[][] CustomFontFamilyData = new [] { | |
new [] { | |
new Tuple<FontAttributes, string>(FontAttributes.None, "fontawesome-webfont.ttf"), | |
new Tuple<FontAttributes, string>(FontAttributes.Bold, "fontawesome-webfont.ttf"), | |
new Tuple<FontAttributes, string>(FontAttributes.Italic, "fontawesome-webfont.ttf"), | |
}, | |
}; | |
protected override bool CheckIfCustomFont (string fontFamily, FontAttributes attributes, out string fontFileName) | |
{ | |
for (int i = 0; i < CustomFontFamily.Length; i++) { | |
if (string.Equals(fontFamily, CustomFontFamily[i], StringComparison.InvariantCulture)){ | |
var fontFamilyData = CustomFontFamilyData[i]; | |
for (int j = 0; j < fontFamilyData.Length; j++) { | |
var data = fontFamilyData[j]; | |
if (data.Item1 == attributes){ | |
fontFileName = data.Item2; | |
return true; | |
} | |
} | |
break; | |
} | |
} | |
fontFileName = null; | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment