UIAccessibility default language throughout the ap

2019-05-04 00:11发布

问题:

We're working on an app that's localized only in the German language and want to add accessibility feature to it. Since the accessibilityLabels are in German, it would be great to always read it in German, regardless of what the user's default system language is.

I noticed one can set that with the accessibilityLanguage property. But it needs to be set on each control repeatedly.

Is there any way to set the accessibility language once globally for every control in the app?

回答1:

Just found out a way shortly after posting the question! :)

You can set accessibilityLanguage directly on UIApplication in AppDelegate. For example, in application:didFinishLaunchingWithOptions:,

application.accessibilityLanguage = @"de";

And it will be applied to all the controls. Tested on iOS 7.



回答2:

You can make a category on NSObject in a header file like this:

@implementation NSObject (Accessibility)

    - (NSString *)accessibilityLanguage {
        return @"de";
    }

@end

Then consider importing it in you prefix header (.pch file) so you don't have to import it everywhere you need it



回答3:

You can do it by inheritance, and use your customised components which by default would have this value set in the way you want. But probably in the existing project it won't be so easy and quick to apply.