Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SanFrancisco (.SFUIText, .SFUI-Regular) fonts issue on iOS 13

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?

like image 752
Maksim Ramanovich Avatar asked Sep 23 '19 13:09

Maksim Ramanovich


1 Answers

System fonts like this are now longer reference-able with 'dot' / . notation as per:

https://developer.apple.com/videos/play/wwdc2019/227/

Starting with iOS 13, you can utilise the new enum UIFontDescriptor.SystemDesign, using regular, rounded, serif or monospaced.

An example of how to create font using descriptors in Swift (see how I'm using the design parameter):

extension UIFont {

    convenience init?(
        style: UIFont.TextStyle,
        weight: UIFont.Weight = .regular,
        design: UIFontDescriptor.SystemDesign = .default) {

        guard let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
            .addingAttributes([UIFontDescriptor.AttributeName.traits: [UIFontDescriptor.TraitKey.weight: weight]])
            .withDesign(design) else {
                return nil
        }
        self.init(descriptor: descriptor, size: 0)
    }
}

like image 185
Ash Cameron Avatar answered Nov 22 '22 12:11

Ash Cameron