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?
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)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With