How to disable the font scaling for the Display alert's in Maui - iOS

Vaibhav Methuku 80 Reputation points

Currently I'm disabling the font scaling in iOS by following this.

Now I want to achieve the same functionality for the display alerts as well. how to achieve this MAUI iOS.

Vaibhav Methuku.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,045 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 27,746 Reputation points Microsoft Vendor


    You mean the Page.DisplayAlert Method, right?

    On iOS platform, it will display an AlertController, see the source code.

    To avoid it, you have to customize the font on AlertController, please refer to the following code:

    (Note: value for key method will call Apple's private Api. As described on Apple's doc - The view hierarchy for this class is private and must not be modified, you could customize a view/control looks like an Alert)

    {#if IOS
    		PopAlert("333", "111", "OK");
    //  DisplayAlert("333", "111", "OK");
        void PopAlert(string Title, string Message, string cancle)
            var alert = UIAlertController.Create(Title, Message, UIAlertControllerStyle.Alert);
            var fontTitle = UIFont.SystemFontOfSize(16);// avoid large text
            var fontMessage = UIFont.SystemFontOfSize(14);
            var titleAtrr = new NSAttributedString(Title, fontTitle);
            var messageAtrr = new NSAttributedString(Title, fontMessage);
            var action = UIAlertAction.Create("OK", UIAlertActionStyle.Default, (action) =>
            alert.SetValueForKey(titleAtrr, new NSString("attributedTitle"));
            alert.SetValueForKey(messageAtrr, new NSString("attributedMessage"));
            var actionArr = new NSAttributedString("OK", fontTitle);
            Microsoft.Maui.ApplicationModel.Platform.GetCurrentUIViewController().PresentViewController(alert, false, () =>
    		{// there is high risk to call the api
                var label = action.ValueForKey(new NSString("__representer"))?.ValueForKey(new NSString("label")) as UILabel;
                label.AttributedText = actionArr;

    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.

0 additional answers

Sort by: Most helpful