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
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://stackoverflow.com/a/20510095/5756850
Prefer using real device to test [UIApplication sharedApplication].preferredContentSizeCategory;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With