Hello,
Welcome to our Microsoft Q&A platform!
I test the ttf
file you provided, the regular
and light
ones look like the same style. You could try to download GraphikBold.otf
, GraphikLight.otf
GraphikRegular.otf
and use these fonts. I'm afraid this is a issue about Graphik Web
font in iOS, I will report it by my internal way. You could also report it in github: https://github.com/xamarin/Xamarin.Forms/issues.
[assembly: ExportFont("GraphikRegular.otf")]
[assembly: ExportFont("GraphikLight.otf")]
[assembly: ExportFont("GraphikBold.otf")]
Xaml
<Label x:Name="boldLabel" Text="Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!" FontFamily="GraphikBold" HorizontalTextAlignment="Center" />
<Label x:Name="lightLabel" Text="Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!" FontFamily="GraphikLight" HorizontalTextAlignment="Center" />
<Label x:Name="regularLabel" Text="Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!Welcome to Xamarin.Forms!" FontFamily="GraphikRegular" HorizontalTextAlignment="Center" />
In addition, this is my test, you could also test other fonts, refer to :
I download some other fonts( GraphikBold.otf
, GraphikLight.otf
) and add them to my project, it works.
So I install the font you provided into my Mac, I got an error when I install the font. Then I add the otf
ttf
files to Resources
folder in iOS project , add the font to info.plist
and print all font name.
** info.plist
**
<key>UIAppFonts</key>
<array>
<string>Graphik-Bold-Web.ttf</string>
<string>Graphik-Light-Web.ttf</string>
<string>Graphik-Regular-Web.ttf</string>
<string>GraphikRegular.otf</string>
<string>GraphikLight.otf</string>
<string>GraphikBold.otf</string>
</array>
Print font name
#if DEBUG
var fontList = new StringBuilder();
var familyNames = UIFont.FamilyNames;
foreach (var familyName in familyNames)
{
fontList.Append(String.Format("Family: {0}\n", familyName));
Console.WriteLine("Family: {0}\n", familyName);
var fontNames = UIFont.FontNamesForFamilyName(familyName);
foreach (var fontName in fontNames)
{
Console.WriteLine("\tFont: {0}\n", fontName);
fontList.Append(String.Format("\tFont: {0}\n", fontName));
}
};
#endif
When I build and run the project, the font name whose font family name is Graphik Web
is deferent every time . In addition, I add three files but it only print one, I'm afraid the other style are not supported for iOS.
only the Bold one
[assembly: ExportRenderer(typeof(Label), typeof(MyLabelRender))]
namespace EmbeddedFontsSample.iOS
{
public class MyLabelRender : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var fontNames = UIFont.FontNamesForFamilyName("Graphik Web");
Control.Font = UIFont.FromName(fontNames[0], 16);
}
}
}
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.