Using custom fonts, regular and bold

z07713z07713 ✭✭USMember ✭✭
edited September 2018 in Xamarin.Forms

I would like to use custom font in my application globally on every Label element. I set:

<Style TargetType="Label">

            <Setter Property="FontFamily"
                    Value="NotoSansRegular.ttf#Noto Sans" />

</Style>

in my App.cs as ordered and it works fine, however when i set the Label's "FontAttributes" property to "Bold" i lose the custom font and even the boldness doesn't work!

What would be the recommended approach for this?

Thanks...

Best Answer

  • z07713z07713 ✭✭ US ✭✭
    Accepted Answer

    well...

    <Style TargetType="Label">
    
        <Style.Triggers>
    
            <Trigger TargetType="Label" Property="FontAttributes" Value="Bold">
    
                <Setter Property="FontFamily"
                        Value="NotoSansBold.ttf#Noto Sans" />
    
            </Trigger>
    
        </Style.Triggers>
    
        <Setter Property="FontFamily"
                Value="NotoSansRegular.ttf#Noto Sans" />
    
    </Style>
    

Answers

  • kingleroygkingleroyg ✭✭ ZAMember ✭✭

    Why not add NotoSansBold font ? and use specific fonts based on FontAttributes ?



  • z07713z07713 ✭✭ USMember ✭✭

    @kingleroyg said:
    Why not add NotoSansBold font ? and use specific fonts based on FontAttributes ?



    if i add NotoSansBold then the bold ones work, the regular ones does not! i want this to be applied globally, not add a single property to every label i already have...

  • z07713z07713 ✭✭ USMember ✭✭
    Accepted Answer

    well...

    <Style TargetType="Label">
    
        <Style.Triggers>
    
            <Trigger TargetType="Label" Property="FontAttributes" Value="Bold">
    
                <Setter Property="FontFamily"
                        Value="NotoSansBold.ttf#Noto Sans" />
    
            </Trigger>
    
        </Style.Triggers>
    
        <Setter Property="FontFamily"
                Value="NotoSansRegular.ttf#Noto Sans" />
    
    </Style>
    

  • SivaShankarArumugamSivaShankarArumugam ✭✭✭ USMember ✭✭✭

    @z07713 How to use different custom font attribute like xxx bold,xxx regualar,xxx light, etc.,

Sign In or Register to comment.