如何从iOS设置中检测动态字体大小更改?

问题描述:

内部设置 - >常规 - >文字大小,更改文字大小后,我必须退出自己的应用以将尺寸应用于

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?

更新:我尝试了以下但有趣的是,字体大小将适用于我BG并启动应用程序TWICE。

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];

}


你听对于 UIContentSizeCategoryDidChangeNotification

Swift 3.0:
NSNotification.Name.UIContentSizeCategoryDidChange