Accessibility Large Text from Settings
Asked Answered
D

1

6

When I try to implement user selected font of text from settings accessibility in my application, unable to get the user selected text size into my app. code is like

let contentSize = UIApplication.sharedApplication().preferredContentSizeCategory

preferredContentSizeCategory always returning same font like UICTContentSizeCategoryL even after changing in setting/accessibility

Dextrorse answered 13/4, 2016 at 11:55 Comment(0)
D
13

add the following code to your viewDidLoad to get notified when font size is changed from settings accessibility.

[[NSNotificationCenter defaultCenter]
                              addObserver:self
                                 selector:@selector(preferredContentSizeChanged:)
                                     name:UIContentSizeCategoryDidChangeNotification
                                   object:nil];

Next, add the following method:

- (void)preferredContentSizeChanged:(NSNotification *)notification {
    self.textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}

This simply sets the text view font to one based on the new preferred size.

Note: You might be wondering why it seems you’re setting the font to the same value it had before. When the user changes their preferred font size, you must request the preferred font again; it won’t be updated automatically. The font returned via preferredFontForTextStyle: will be different when the font preferences are changed.

EDIT:

Refer to this post: https://mcmap.net/q/236911/-how-to-use-a-custom-font-with-dynamic-text-sizes-in-ios7

Prefer using real device to test [UIApplication sharedApplication].preferredContentSizeCategory;

Denys answered 13/4, 2016 at 12:6 Comment(3)
Thanks for your response, your code always returns ** font-family: ".SFUIText-Regular"; font-weight: normal; font-style: normal; font-size: 14.00pt** even after text size changes in accessibility. My aim is to get lower font if i select less in accessibility and more font if i select more in accessibility text size. Do you have any idea ?Dextrorse
Hey, please check here : (Also prefer using real device to test this) https://mcmap.net/q/236911/-how-to-use-a-custom-font-with-dynamic-text-sizes-in-ios7Denys
Yes, I followed that link, but [UIApplication sharedApplication].preferredContentSizeCategory always returns same value .Dextrorse

© 2022 - 2024 — McMap. All rights reserved.