Hello,
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");
#else
// DisplayAlert("333", "111", "OK");
#endif
}
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.DismissModalViewController(true);
});
;
alert.SetValueForKey(titleAtrr, new NSString("attributedTitle"));
alert.SetValueForKey(messageAtrr, new NSString("attributedMessage"));
alert.AddAction(action);
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.