Hi,
I'm using Xamarin 4 with Xamarin.Forms 2.0. I created a custom renderer on Android to display a custom font. Now I would like to link the XAML FontAttributes property value (e.g. Bold) to a specific font type, e.g. (Open Sans Bold.ttf). How can I do this?
PCL XAML:
<controls:ExtendedLabel
Text="Welcome"
FontFamily="2Dumb"
HorizontalOptions="CenterAndExpand"/>
Android
namespace MolinaMemberApp.CustomControls
{
public class ExtendedLabel : Label {}
}
[assembly: ExportRenderer(typeof(ExtendedLabel), typeof(ExtendedLabelRenderer))]
namespace MolinaMemberApp.Droid.CustomControls
{
public class ExtendedLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e)
{
base.OnElementChanged(e);
var label = (TextView)Control; // for example
Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, "2Dumb_webfont.ttf");
label.Typeface = font;
}
}
}