我已经在xamarin中创建了一个自定义导航页面,以便更改导航栏中工具栏项目的字体。
一切顺利,但是由于某些原因,字体没有在所有工具栏项上更改,只是最后一项。
=”
您可以看到,除了字体之外,我还尝试将颜色更改为红色,但是这同样也适用于最后一项。
XAML:
<ContentPage.ToolbarItems> <ToolbarItem x:Name="MenuItem1" Order="Primary" Text="x1" Priority="0" /> <ToolbarItem x:Name="MenuItem2" Order="Primary" Text="x2" Priority="1" /> <ToolbarItem x:Name="MenuItem3" Order="Primary" Text="x3" Priority="2" /> <ToolbarItem x:Name="MenuItem4" Order="Primary" Text="x4" Priority="3" /> </ContentPage.ToolbarItems>
iOS:
public class FontAwesomeNavigationPageRenderer : NavigationRenderer { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if(e.NewElement != null) { var att = new UITextAttributes { Font = UIFont.FromName("FontAwesome5Pro-Light", 18), TextColor = UIColor.Red }; UIBarButtonItem.Appearance.SetTitleTextAttributes(att, UIControlState.Normal); } } }
我想念什么?
我已经在xamarin中创建了一个自定义导航页面,以便更改导航栏中工具栏项目的字体。一切顺利,但是所有工具栏上的字体都没有改变,只是...
NavigationRenderer is a UINavigationController in iOS,因此您可以执行以下操作:
由于上述评论中@ iSpain17的一些帮助,我终于设法完成了这项工作。