How can I prevent the device font size effect of a MAUI iOS app?

Vaibhav Methuku 60 Reputation points
2024-04-30T07:59:29.0966667+00:00

When ever I change the font size in the iOS device, that font size is effecting on the MAUI application. I want to restrict that.


I want to restrict that in my maui application. I can able to do that in the Android application by adding this piece of code in the main activity

 protected override void AttachBaseContext(Context @base)
 {
     Configuration configuration = new(@base.Resources.Configuration)
     {
         FontScale = 1.0f
     };
     ApplyOverrideConfiguration(configuration);
     base.AttachBaseContext(@base);
 }

How to achieve the similar functionality in the iOS .?

Thanks
Vaibhav Methuku.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,958 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,946 Reputation points Microsoft Vendor
    2024-05-01T02:58:04.6066667+00:00

    Hello,

    On iOS platform, you cannot avoid this feature by setting configurations. The only way is to set scaling Fonts Automatically, and MAUI provide a FontAutoScalingEnabled property for text-based controls such as Label, Button, Editor and so on.

    For more details, please refer to Fonts in .NET MAUI - .NET MAUI | Microsoft Learn

    <Label ...
           FontAutoScalingEnabled="False" />
    <Button FontAutoScalingEnabled="False"
                   />
    
                <Entry FontAutoScalingEnabled="False"></Entry>
    
                <Editor FontAutoScalingEnabled="False"></Editor>
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.