Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Accessibility font size

Hello.

My app is using a mix of controls (such as Label) without any size attribute set, sometimes using font size name ("medium", "small", ...) and sometimes using actual integer value.

This is working fine until accessibility settings are changed. Don't know exactly where the corresponding setting exists in Android but on iOS you find that under Settings > General > Accessibility > Larger Text where you can move a slider to make it even slightly smaller to slightly larger to much (much) larger.

Working with controls such as TableView with native cell types properly inherits the size defined under Accessibility but Labels for instance, even when not specifying a particular font size (/name), are not inheriting this setting and still show the standard size.

Question is how to best implement this handling so that basically everything is scaled up (or low) according to the accessibility setting? Ideally of course, I'd like to still be able to specify "medium", "large", ... (maybe even "points"? but not sure about this one) and just get an additional zoom scaling applied. This is how I would expect it to work.

Any hint?

Best Answer

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    Nobody seems to be interested in this problematic but I dug into this question and found a useful resource: https://forums.xamarin.com/discussion/43575/getting-android-ios-accessibility-font-sizes

    In short for summarizing what I discovered:

    • On Android everything scales up/down automatically, even when using fixed (instead of named) font size in labels, ...
    • An option I will investigate is binding the fontsize or control height to some custom binding convertor that will increase/decrease the actual requested "size" taking the accessibility factor into account.

Answers

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    Nobody seems to be interested in this problematic but I dug into this question and found a useful resource: https://forums.xamarin.com/discussion/43575/getting-android-ios-accessibility-font-sizes

    In short for summarizing what I discovered:

    • On Android everything scales up/down automatically, even when using fixed (instead of named) font size in labels, ...
    • An option I will investigate is binding the fontsize or control height to some custom binding convertor that will increase/decrease the actual requested "size" taking the accessibility factor into account.
  • XavierPerseguersXavierPerseguers CHMember ✭✭✭

    In case this helps someone else:

    public double AccessibilitySizeFactor {
        get {
            var sizeCategory = UIKit.UIApplication.SharedApplication.PreferredContentSizeCategory;
            double factor = 1;
    
            // Factors have been reverse-engineered by comparing a font size of 16pt (= 45px)
            // with the corresponding sizes in ListView
            double baseSize = 45D;
            switch (sizeCategory)
            {
                case "UICTContentSizeCategoryXS":
                    factor = 39 / baseSize;
                    break;
                case "UICTContentSizeCategoryS":
                    factor = 42 / baseSize;
                    break;
                case "UICTContentSizeCategoryM":
                    factor = 1;
                    break;
                case "UICTContentSizeCategoryL":
                    factor = 48 / baseSize;
                    break;
                case "UICTContentSizeCategoryXL":
                    factor = 53 / baseSize;
                    break;
                case "UICTContentSizeCategoryXXL":
                    factor = 57 / baseSize;
                    break;
                case "UICTContentSizeCategoryXXXL":
                    factor = 63 / baseSize;
                    break;
            }
    
            return factor;
        }
    }
    
  • JohnHardmanJohnHardman GBUniversity admin

    @XavierPerseguers said:
    Nobody seems to be interested in this problem

    Thankfully some of us are. Unfortunately though, there are many developers and managers who have no interest in accessibility (or many of the other 'ilities). Accessibility is often ignored even in scenarios where there are legal requirements to implement it. It would be good if the big name software companies encouraged developers to support accessibility, by providing APIs that support it, and by ensuring that sample code implements it. Unfortunately, sample code is rarely written in a production-ready way. I've raised this before with Xamarin, but to no avail :-(

Sign In or Register to comment.