I have used custom renderer for setting up a font.. The issue is when I change the text for the label the font style disappers..
Provided is my custom renderer code.. Can anyone tell me what I'm doing wrong??
[assembly: ExportRenderer (typeof (MyLabel), typeof (MyLabelRenderer))]
namespace FormsProj.Droid
{
public class MyLabelRenderer : LabelRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Label> e)
{
base.OnElementChanged (e);
var label = (TextView)Control;
Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "Raleway-Regular.ttf");
label.Typeface = font;
}
}
}
Update #1 This is my Code Shared Project using System; using Xamarin.Forms;
namespace FormsProj
{
public class MyLabel:Label
{
}
}
Code Where I'm using MyLabel
var Thankyoutxt = new MyLabel {
XAlign = TextAlignment.Center,
Text = "Thank You",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
TextColor = Xamarin.Forms.Color.White,
FontAttributes = FontAttributes.Bold,
Style = Device.Styles.CaptionStyle,
FontFamily = ColorandFont.FontName,
};
On a click of the button I will change text, By that time the font changes back without custom font..
Thanks in advance.. :)