Xamarin.forms: [Bug] iOS FontSize is calculated incorrectly

Created on 22 Aug 2019  路  9Comments  路  Source: xamarin/Xamarin.Forms

Description

On iOS named fontsizes are calculated incorrectly usually resulting in 1 point less than expected.

Steps to Reproduce

  1. Executing
    var result = new FontSizeConverter().ConvertFromInvariantString(nameof(NamedSize.Micro));
    or add a label with fontsize micro

Expected Behavior

NamedSize.Micro should return 12 with default settings

Actual Behavior

Returns 11

Basic Information

I think the issue lies in https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Forms.cs

The font scaling factor is calculated on line 188 like this.
_fontScalingFactor = (double)UIFont.PreferredBody.PointSize / 18f;
I think it should be :
_fontScalingFactor = (double)UIFont.PreferredBody.PointSize / 17f;

Why?
The default UIFont.PreferredBody.PointSize is 17 on my emulator iPhone 7 iOS 12.2.
Also on the Apple guidelines https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/
It states that the default body Size in points is 17.

And on line 224 in the source it is also stated that
// iOS docs say default button font size is 15, default label font size is 17 so we use those as the defaults.

  • Version with issue: Xamarin.Forms 4.1.0.618606
  • Last known good version: Xamarin.Forms 4.0.0.425677
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:

    • iOS: 8.0

  • Nuget Packages: Xamarin.Forms
  • Affected Devices: only tested on iPhone 7 iOS 12.2
4.1.0 4 regression in-progress iOS 馃崕 bug

Most helpful comment

Any news on this?

We need to upgrade Xamarin.Forms to version 4.3 (from 3.6) in our product
because of the relative source binding in 4.3. However, we use named font sizes a lot
and are not happy with the smaller fonts on iOS. We need to solve this somehow
but the best thing would be if it was solved in Xamarin.Forms.

All 9 comments

@RobWos Can you please attach a small project that demonstrates this issue? Thanks!

IncorrectFontSize.zip
Just checked the last known good Xamarin.Forms version is 4.0.0.709238, the first version with the bug is 4.1.0.555618.

Instructions :
Run the app on iOS note down the font sizes.
Update Xamarin.Forms to version 4.1.0.555618.
Run the app on iOS note down the font sizes.
Compare the results

This regression was introduced when we added the scaling #5985
@Clancey opinions ?
https://github.com/xamarin/Xamarin.Forms/blame/master/Xamarin.Forms.Platform.iOS/Forms.cs#L188

Any news on this?

We need to upgrade Xamarin.Forms to version 4.3 (from 3.6) in our product
because of the relative source binding in 4.3. However, we use named font sizes a lot
and are not happy with the smaller fonts on iOS. We need to solve this somehow
but the best thing would be if it was solved in Xamarin.Forms.

I Agree with Blomman1. We have the same problem.

We have the same problem as Blomman1. This might delay our next release!

We are also troubled by this. We can't upgrade Xamarin Forms version.

We solved this by disabling the font scaling feature for now.

Xamarin.Forms.Application.Current.On<iOS>().SetEnableAccessibilityScalingForNamedFontSizes(false);

closed by #9821

Was this page helpful?
0 / 5 - 0 ratings