Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Dynamic Font size changes from iOS Settings?

Tags:

ios

uifont

Inside settings->general->text size, after changing the text size, I'd have to exit my own app to have the sizes applied to

 [UIFont preferredFontForTextStyle:..] 

Is there a delegate or notification to notify my app to re-apply the new sizes?

Update: I tried the following but interestingly, the font size will apply after I BG and launch the app TWICE.

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fromBg:) name:UIApplicationDidBecomeActiveNotification object:nil];  }    -(void) fromBg:(NSNotification *)noti{      self.headline1.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];     self.subHeadline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];     self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];     self.footnote.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];     self.caption1.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];     self.caption2.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; //    [self.view layoutIfNeeded];  } 
like image 687
mskw Avatar asked Sep 23 '13 03:09

mskw


People also ask

Why did my font size suddenly changed on iPhone?

If the font changes, it's because the app you have open changed it, not you. But that doesn't mean you can't edit the text at all. Every iPhone lets you change the font size, making it either bigger or smaller. This is great for users with impaired vision, or with magnified screens.

What is dynamic font in iOS?

The Dynamic Type feature allows users to choose the size of textual content displayed on the screen. It helps users who need larger text for better readability. It also accomodates those who can read smaller text, allowing more information to appear on the screen.

How do you make text dynamic on iPhone?

Dynamic Type is a feature that enables the app's content to scale based on the user's preferred content size. The preferred content size can be found in Settings -> Accessibility -> Display & Text Size -> Larger Text.


1 Answers

You listen for the Size Change Notification on UIContentSizeCategory.

Swift 3.0: NSNotification.Name.UIContentSizeCategoryDidChange

Swift 4.0 or later: UIContentSizeCategory.didChangeNotification

like image 135
Dave DeLong Avatar answered Sep 21 '22 07:09

Dave DeLong