[英]How do I tell all my Auto Layout constraints to update themselves? (For example when user updates their system size/Dynamic Type)?
I'm adding Dynamic Type support to my app in iOS 7, and right now when the user changes their System Font Size and then quits and reopens the app, it updates it delightfully. 我在iOS 7中为我的应用添加了动态类型支持,现在当用户更改系统字体大小然后退出并重新打开应用程序时,它会更新它。 However, when just launching back to the app I can't seem to get it to work. 但是,当刚刚启动回应用程序时,我似乎无法让它工作。
I added an observer: 我添加了一位观察员:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentSizeDidChange) name:UIContentSizeCategoryDidChangeNotification object:nil];
Which calls the following method when the user changes their size: 当用户更改其大小时,会调用以下方法:
- (void)contentSizeDidChange {
[self.tableView invalidateIntrinsicContentSize];
[self.tableView reloadData];
}
But the type size in my cells doesn't change at all (though the height of the cell does). 但我的细胞中的类型大小根本没有变化(尽管细胞的高度确实如此)。 Is this because I subclassed UITableViewCell for my cells? 这是因为我为我的细胞分类了UITableViewCell吗?
EDIT: 编辑:
Here's what I have in my UITableViewCell
subclass: 这是我在UITableViewCell
子类中的内容:
- (void)contentSizeDidChange {
self.fullCellURLLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
self.timeLeftLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
self.timeLeftLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
self.fullCellPreviewLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
}
I'm going to guess here (since I did not do it) that you have to reset the text on each text object to the "preferred" size you want. 我将在这里猜测(因为我没有这样做)你必须将每个文本对象上的文本重置为你想要的“首选”大小。 When you use that method it returns a static UIFont - the font itself won't update "inside" the control. 当您使用该方法时,它返回一个静态UIFont - 字体本身不会在控件内“更新”。
So do this test with a static view and a few uitextfields - who knows how the system will change the fonts as the size increases? 所以使用静态视图和一些uitextfields进行此测试 - 谁知道系统将随着大小的增加更改字体? Try that in a demo project first, before you refine your real app. 在优化真实应用之前,首先在演示项目中尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.