iosswiftuitableviewcocoa-touchuitraitcollection

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?
}

Solution

  • 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)