After updating to iOS 13 my fonts failed. In my App.xaml I had:
<OnPlatform x:Key="FontFamilyRegular" x:TypeArguments="x:String">
<On Platform="iOS">.SFUIText</On>
</OnPlatform>
<OnPlatform x:Key="FontFamilyMedium" x:TypeArguments="x:String">
<On Platform="iOS">.SFUIText-Medium</On>
</OnPlatform>
<OnPlatform x:Key="FontFamilyBold" x:TypeArguments="x:String">
<On Platform="iOS">.SFUIText-Semibold</On>
</OnPlatform>
It all worked fine until I updated my device to iOS 13.
I debugged iOS project and find out that font names could be changed to: .SFUI-Regular, .SFUI-Semibold - but these do not work neither. Also I tried updating to the latest Xamarin version - no luck.
How can I use these 3 font families in the newest iOS version?
same here!
@MJRomka Can you please attach a small project that demonstrates this issue? Thanks!
testfonts.zip
As you can see red color is applied, but the font family is broken.
We believe you! But could you please attach a reproduction project?
Don鈥檛 you see testfonts.zip file I attached to the previous message?
Okay, the problem is that as of iOS 13, we're not supposed to load system fonts by name anymore. (Technically it's been advised against for a while, but iOS 13 actually enforces it by just giving you back Times New Roman when you ask for a system font.)
So, in Xamarin.Forms.Platform.iOS.FontExtensions.cs in the _ToNativeFont
method, before we attempt to load the font using UIFont.FromName
, we should check the family name for the .SF
prefix; if it's there, we need to parse the UIFontWeight (Regular, Thin, Bold, etc.) and use UIFont.SystemFontOfSize(size, weight);
.
That should give us the correct fonts going forward while remaining backward-compatible.
Some reference material: https://developer.apple.com/videos/play/wwdc2019/227/ (relevant bits start around 2:46)
Could you please give an official answer: should I go ahead and change my code overriding setting font family for iOS or you are going to fix it? Any estimations you can give in the second case?
@MJRomka I'm not from the official team but I'd suggest you to change your code for now and just leave the font family attribute empty on iOS to use the system font. However, you can set the font attribute bold to have at least a bit of differences in your fonts. Another alternative is that you write your own custom renderer to use UIFont.SystemFontOfSize(size, weight) by yourself.
In the meantime I try to contribute to this bug.
Thank you @JFMG
The first option you suggested is actually a workaround I made: leaving a font family blank and using font Bold attribute, but it gives only two options of font weight when I need 3. And this is not a long term approach since I need to have separate branches for Android and iOS.
The second option you suggested sounds like a long term solution, but it requires resources which I'd not spend if Xamarin team is about to fix this really annoying issue.
@hartez I provided a fix. Please have a look and let me know if it fits.
@MJRomka If my fix is getting accepted, it will be available in XF 4.4.0
@samhouts what needs to be done to get this merged into 4.4.0? I'd like to help out if anything is needed.
Fixed by #8418
thanks so much for merging this in @rmarinho
I'm guessing this will be in the next 4.4 release?
@seanrodda The fix should be in the current stable 4.4.0.991265 which was just released.
@JFMG Thanks, I thought so too, however it does not seem to be in that build. I also decompiled and checked the code from the nuget package.
@seanrodda Looks like the fix will come in a later 4.4.0 release. Probably @samhouts knows more.
Yeah it seems this just missed the cut for the 4.4 stable release. It should be available in the first 4.4 service release and the 4.5-pre1 which should be available soon.
There appears to be a partial regression in 4.5.0.356, I am getting these messages in the log:
CoreText note: Client requested name ".SFUIText-Medium", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].
However I don't see anything in my app actually rendering in TimesNewRoman. I will test in a repro project asap.
@esenciadev Any progress on the repro project?
@samhouts @kingces95 Any update to this. It seems to have been forgotten about but messages still appear in the logs.
The warning messages are new. But since this is a new behavior and the issue to actually see the Times New Roman font already got fixed, I suggest you to open a new issue.
@rscholey Are you seeing the messages in a brand new solution too? I just tried with latest Forms version and no warning messages appear. This sounds like some 3rd-party library, which is using older Forms version (before the fix).
Most helpful comment
@MJRomka If my fix is getting accepted, it will be available in XF 4.4.0