Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

traitCollection.preferredContentSizeCategory.isAccessibilityCategory for iOS 10

The following code works great on iOS11 to detect if the user has set LARGE FONT in their accessibility settings.

However, I need to support this in iOS10 as well. How can I accomplish this?

Right now the code looks like this:

if #available(iOS 11.0, *) {
    if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
        return UITableViewAutomaticDimension
    } else {
        return someSpecificHeight
    }
} else {
    // how to detect is isAccessibilityCategory on non-iOS11 devices?
    // is there some ugly fallback I don't know about?
}
like image 398
Jeff Avatar asked Feb 04 '26 05:02

Jeff


1 Answers

Okay, based on @Jefflovejapan's answer, it looks like I can do this:

 let sizeCategory = traitCollection.preferredContentSizeCategory

        if sizeCategory == .accessibilityMedium
     || sizeCategory == .accessibilityLarge
     || sizeCategory == .accessibilityExtraLarge
     || sizeCategory == .accessibilityExtraExtraLarge
     || sizeCategory == .accessibilityExtraExtraExtraLarge {
            return UITableViewAutomaticDimension
        } else {
            return someSpecificHeight
        }

Ugly, but I think it does the trick..

I have to do all the == comparisons, because that seems like the only supported operator in iOS10 (all the other ones apparently are added in iOS11)

like image 61
Jeff Avatar answered Feb 05 '26 19:02

Jeff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!