Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Custom font for Label

$
0
0

I want a custom font for a label in my app.
I followed the guide ( http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/fonts/#Using_a_Custom_Font ) and created a class named KomikaLabel in my shared project. The font is in Assets/fonts in the android project. Then I added this code to the android project:

    [assembly: ExportRenderer (typeof (DonnerWetter.KomikaLabel), typeof (DonnerWetter.Android.KomikaRenderer))]
    namespace DonnerWetter.Android {
        public class KomikaRenderer : LabelRenderer {
            protected override void OnElementChanged (ElementChangedEventArgs<Label> e) {
                base.OnElementChanged (e);
                var label = (TextView)Control;
                Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "KOMTXT__.ttf");
                label.Typeface = font;
            }
        }
    }

I tested it on two different devices but I just get a runtime exception "native typeface cannot be made".
Did I miss something?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>