Ios7 iOS 7 UIKit文本大小调整

Ios7 iOS 7 UIKit文本大小调整,ios7,uikit,accessibility,Ios7,Uikit,Accessibility,我在应用程序中使用iOS 7文本样式。当用户更改它们时,我希望调整我的UI 我知道我可以注册UIContentSizeCategoryDidChangeNotification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentSizeCategoryDidChangeNotification:) name:UIContentSizeCategoryDidCh

我在应用程序中使用iOS 7文本样式。当用户更改它们时,我希望调整我的UI

我知道我可以注册
UIContentSizeCategoryDidChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(contentSizeCategoryDidChangeNotification:)
      name:UIContentSizeCategoryDidChangeNotification object:nil];
但我真的不确定如何更新字体大小,除此之外:

- (void)contentSizeCategoryDidChangeNotification:(NSNotification *)notification {
    _label1.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    _label2.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
    _label3.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    _label4.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    _label5.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    _label6.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
    [self.view setNeedsLayout];
    [self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
}

我真的不想在代码中指定每种字体样式,因为我已经在故事板中指定了它们,但我不知道在这里还能做什么。有更好的解决方案吗?

如果有字体
f
,请拨打:

NSString* style = [[f fontDescriptor] objectForKey:UIFontDescriptorTextStyleAttribute];
现在您可以调用
[UIFont preferredFontForTextStyle:style]
生成新字体


因此,不必将每个标签的文本样式硬编码到代码中,但是,是的,必须为每个标签重新设置字体,因为(获取此)动态类型不是动态的。

描述符上缺少fontAttributes,对吗?一点也不
preferredFontForTextStyle:
只接受一个参数,这是我从现有字体中提取的参数。事实上,用于动态类型的实际字体是私有信息,您永远不应该查看它。啊,好的。我不知道你的代码会编译,但它会。我以为您缺少了一个
[[f fontDescriptor]fonttributes]
,但是从文档
objectForKey:
中,无论如何都只是映射了一下。我的错误。:)我误解了你的问题,就这样!:)