Xamarin v4.4.0.991640 (latest at this time)
I have implement code so that the App (Android and iOS) use a custom font. I have also implemented a Custom Renderer so that the Navigation Header also uses the custom font. Android is working fine (in both cases), but in iOS, the font is not used at all?
In iOS I have done the following:
The ttf file is in Resources/Fonts/Promento.ttf (BundleResource)
In Info.plist I have
<key>UIAppFonts</key>
<array>
<string>Fonts/Promento.ttf</string>
</array>
In a ResourceDictionary I have:
<OnPlatform x:TypeArguments="x:String" x:Key="Promento">
<On Platform="Android" Value="Promento.ttf#Promento" />
<On Platform="iOS" Value="Promento" />
</OnPlatform>
The font just does not seem to be picked up. In my Custom Renderer I have:
[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.NavigationPage), typeof(CustomNavigationRenderer))]
namespace GlueStep.Mobile.iOS.Renderers
{
public class CustomNavigationRenderer : NavigationRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (!(e.NewElement is null))
{
var attributes = new UITextAttributes();
attributes.Font = UIFont.FromName("Promento", 24);
UINavigationBar.Appearance.SetTitleTextAttributes(attributes);
}
}
}
}
What I have noticed is that if I set a break point on this line and then visit a Navigation Page:
UINavigationBar.Appearance.SetTitleTextAttributes(attributes);
Then attributes.Font is always null?
Can anyone see what I am missing?
attributes.Font
stillnull
? – SushiHangover