How can we achieve large font accessibility in Xamarin.iOS?

951 views Asked by At

My application is developed using Xamarin.iOS and I need to make it accessible. We couldn't find any help to achieve large text accessibility in xamarin.iOS. I found this link which explains how to achieve it in Xamarin.Forms and this about MonoTouch. Could someone help me how to achieve Large text accessibility on Xamarin.iOS.

2

There are 2 answers

1
Cheesebaron On

MonoTouch and Xamarin.iOS are the same thing, just a different name.

It is achieved in the exact same way, where you set the Font property of your UILabel or UITextField to one of the available fonts in the UIFont static class like so:

var label = new UILabel
{
    Font = UIFont.PreferredBody
};

This should automatically scale the fonts according to your Accessibility settings on iOS.

6
SushiHangover On

Assign one of the UIFontTextStyles to your UI elements and when the app starts the element's text size will be set based upon the UIFontTextStyle and the user's current Accessibility Larger Text setting:

var uiLabel = new UILabel(new CGRect(40, 40, 200, 40));
uiLabel.Text = "StackOverflow";
uiLabel.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Body);
View.AddSubview(uiLabel);

If you want to dynamically response to the Accessibility Larger Text changes so the user does not have to restart your app, subscribe to UIContentSizeCategoryDidChangeNotification and update your views:

NSNotificationCenter.DefaultCenter.AddObserver(
    new NSString("UIContentSizeCategoryDidChangeNotification"),
    (NSNotification obj) =>
    {
        Console.WriteLine("Update layouts/subviews/layers/etc...");
        View.SetNeedsLayout();
    },
    null
);