0
votes

I am attempting to use a FontAwesome font in a UIBarButtonItem in a NavBar in a Xamarin Forms Project.

My XAML code

<TabbedPage.ToolbarItems>
    <ToolbarItem Command="{Binding CreateNewConversation}" Text="&#xf067;" x:Name="NewConversationButton"></ToolbarItem>
</TabbedPage.ToolbarItems>

My CustomRenderer.cs code called inside of ViewWillAppear

var _font = UIFont.FromName("Font Awesome 5 Free", 18f);

var rightBarButtonTextAttributes = new UITextAttributes
{
    Font = _font,
    TextColor = UIColor.FromRGB(255, 194, 32),
    TextShadowColor = UIColor.Clear
};

this.NavigationController.TopViewController.NavigationItem.RightBarButtonItem.SetTitleTextAttributes(rightBarButtonTextAttributes, UIControlState.Normal);

I can tell that the attributes are being applied as I can see the color of the text update but I am getting a ? with a square border around it. I've set a breakpoint and _font is being set with the correct font. Is there something glaringly obvious that I am doing wrong?

Update:

The issue was the lack of being able to apply a bold font weight to the UIBarButtonItem, which I'm still not sure how to do. I am able to use a different icon but whenever I change a tab the icon goes back to a square around a ? and loses its TintColor.

1
Font Name appears to be correct but is the font registered properly : stackoverflow.com/a/48191854/4984832SushiHangover
I think if it wasn't there would be a nullreference exception that the font could not be instanciatedGerald Versluis
Did you find a solution for this? I'm trying to use the FontAwesome icons in my ToolBar - do I need a custom renderer?rejy11
It had to be a character that FontAwesome has a bold font weight for.tuckerjt07

1 Answers

1
votes

Double-check that you are using the right icon code &#xf067; and if that is available in the font.

Since you're not getting any errors, the font should be found and registered right etc. It looks like iOS is unable to locate this specific character code within your font file.