FontAwesome Pro and xamarin.ios only one font can be active

后端 未结 3 2027
不知归路
不知归路 2020-12-10 15:56

So I have been looking for an answer to this.

I can\'t get all 3 fonts in FontAwesome Pro to work with my xamarin native (iOS) to work.

I do use

         


        
相关标签:
3条回答
  • 2020-12-10 16:16

    To use Font Awesome 5 Pro in Xamarin.Forms

    Use it like below... (Thanks to the helpful code of SushiHangover) * Font Awesome 5 Brands *-- FontAwesome5BrandsRegular * Font Awesome 5 Pro *-- FontAwesome5ProLight *-- FontAwesome5ProRegular *-- FontAwesome5ProSolid

    App.Xaml.cs

            Current.Resources = new ResourceDictionary();
            // Font awesome
            Current.Resources["FontawesomeSolid"] = Device.RuntimePlatform == Device.iOS ? "Font Awesome 5 Pro" : "fa-solid-900.ttf#Font Awesome 5 Pro";
            Current.Resources["FontawesomeRegular"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5Regular" : "fa-regular-400.ttf#Font Awesome 5 Pro";
            Current.Resources["FontawesomeLight"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProLight" : "fa-light-300.ttf#Font Awesome 5 Pro";
            Current.Resources["FontawesomeBrands"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProBrands" : "fa-brands-400.ttf#fFont Awesome 5 Pro";
    
    
            Current.Resources.Add("ShareIconLabel", new Style(typeof(Label))
            {
                Setters =
                {
                    new Setter { Property = Label.TextColorProperty, Value = Color.White},
                    new Setter { Property = View.HorizontalOptionsProperty, Value = LayoutOptions.End},
                    new Setter { Property = View.VerticalOptionsProperty, Value = LayoutOptions.Center},
                    new Setter { Property = AbsoluteLayout.LayoutBoundsProperty, Value = new Rectangle (0.90, 0.5, 0.2, 1)},
                    new Setter { Property = AbsoluteLayout.LayoutFlagsProperty, Value = AbsoluteLayoutFlags.All},
                    new Setter { Property = Label.FontSizeProperty, Value = 30},
                    new Setter { Property = Label.FontFamilyProperty, Value = Current.Resources["FontawesomeLight"] },
                    new Setter { Property = Label.TextProperty, Value = "\uf1e0" } // Share Icon
                }
            });
    

    MySharePage.Xaml

            <AbsoluteLayout
                AbsoluteLayout.LayoutBounds="0,1,1,0.07"
                AbsoluteLayout.LayoutFlags="All"
                BackgroundColor="{x:Static localColors:Constants.MyOrange} ">
                <Label
                    Style="{StaticResource RicoShareLabel}">
                    <!--<Label.GestureRecognizers>
                        <TapGestureRecognizer
                            Tapped="OnSocialShareClicked" />
                    </Label.GestureRecognizers>-->
                </Label>
            </AbsoluteLayout>
    

    0 讨论(0)
  • 2020-12-10 16:21

    Those fonts also have Postscript family name defined you can use instead of the primary family name.

    I do not have a pro license, but the free v5 show:

      * Font Awesome 5 Free
      *-- FontAwesome5FreeRegular
      *-- FontAwesome5FreeSolid
    

    So you can:

    var font = UIFont.FromName(@"FontAwesome5FreeSolid", 20);
    var font = UIFont.FromName(@"FontAwesome5FreeRegular", 20);
    

    FYI: To display those names, use the following:

    foreach (var familyNames in UIFont.FamilyNames.OrderBy(c => c).ToList())
    {
        Console.WriteLine(" * " + familyNames);
        foreach (var familyName in UIFont.FontNamesForFamilyName(familyNames).OrderBy(c => c).ToList())
        {
            Console.WriteLine(" *-- " + familyName);
        }
    }
    
    0 讨论(0)
  • 2020-12-10 16:37

    iOS just loads the font by its 'PostScript Name'. You can rename your TTF file to match that PostScript name, then it will be easier to use it properly.

    0 讨论(0)
提交回复
热议问题