-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System fonts such as ".SFUI-Semibold" are not applied on iOS #15882
Comments
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
I see we've had some issues like this in the past. I wonder if we need to (re)apply something like this again: xamarin/Xamarin.Forms#8418 |
Yeah there's really no support to articulate Font weights independent of the font itself you specify in MAUI today. We talked about how to do this nicely awhile ago: #1018 It looks like as Gerald pointed out that ".SFUI" is a bit of a magic string in Forms, though I'm not necessarily against the idea of introducing something in MAUI at least for System fonts only, to articulate font weight... We'd need to come up a standard set of values that work reasonably well across platform, for instance |
The existing behavior from XF should be supported in MAUI since a lot of apps that are being migrated at the moment will rely on this. Adding fonts manually is a workaround, but only for fonts that are available and that don't increase the app size drastically. The San Francisco font family is quite large and I don't think it's feasible to add it. |
Update: It seems to work on MacCatalyst, if that is of any help. |
Yes, I tried applying the changes in this pull request via a handler mapper and it works. But the downside is, I have to do it separately for Labels and Buttons. private static void MapSystemFont(ILabelHandler handler, IFontElement label)
{
var fontFamily = label.FontFamily;
if (!fontFamily.StartsWith(".SFUI", StringComparison.InvariantCultureIgnoreCase)) return;
var size = (float)label.FontSize;
var fontWeight = fontFamily.Split('-').LastOrDefault();
if (!string.IsNullOrWhiteSpace(fontWeight) && Enum.TryParse<UIFontWeight>(fontWeight, true, out var uIFontWeight))
{
handler.PlatformView.Font = UIFont.SystemFontOfSize(size, uIFontWeight);
}
else
{
handler.PlatformView.Font = UIFont.SystemFontOfSize(size, UIFontWeight.Regular);
}
} |
@returnZro That workaround works, which is great. I'll use this for the time being. Thank you for this ❤️ |
Sadly, I couldn't find a workaround for Android system font aliases
@jfversluis - any suggesstions for a workaround on Android? |
@returnZro I believe this is fixed here #15759 maybe there is some hint in there to come up with a workaround until it's released |
Thanks @jfversluis !! I was able to apply the changes from that pull request locally. Any idea when can we expect that changes to be released? |
@returnZro @jfversluis It would be great if it could make it's way into the .NET 8.0 release in November. However, even that's still a long ways in modern software release cycles, so maybe this can be picked up in @PureWeen's bug fixes and workarounds package? |
It will be in .NET 8 for sure. Maybe sooner, but not very likely. |
For now I've created a PR which fixes the already included code and previous XF behaviour of being able to specify ".SFUI-Bold" as a font. Given the code was already there, this feels more like a bug for now than a "we overhauled the font system and this doesn't make sense anymore". I'd still like to eventually have a nicer way to articulate this, and for Apple, there's I could see a convention something like: Out of scope here, but something to consider longer term. |
Description
In Xamarin.Forms it is possible to use platform-specific system fonts, such as
sans-serif-medium
on Android and.SFUI-Semibold
on iOS, without having to import them manually.Now, using the
.SFUI-Semibold
font fails on iOS, it defaults to Times New Roman, which is the expected behavior for fonts that are unknown on iOS, AFAIK.The code used for Xamarin.Forms and MAUI is the same and looks like this:
Side-by-side comparison of Xamarin.Forms (correct, left) and .NET MAUI (incorrect, right):
I've also tried removing the "." in front of the font name. When I do that, it doesn't default to Times New Roman, but instead a different font (or font style) is used.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/ewerspej/maui-ios-system-font
Version with bug
7.0.49
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 16.4 (at least)
Did you find any workaround?
Not really.
One possibility would be to manually add the gigantic SF Pro font family from Apple directly as a MauiFont asset, but that's far from ideal due to the sheer size of it.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: