简体   繁体   English

如何告知所有自动布局约束自行更新? (例如,当用户更新其系统大小/动态类型时)?

[英]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.

相关问题 我如何使自己的细胞自动调整大小? - How do I get my cells to auto-size themselves? 如果我想在之后设置自动布局约束的动画,我该如何修改我的UIView扩展? - How do I have to modify my UIView extension if I wanted to animate the auto layout constraints afterward? 在主视图顶部添加新视图(例如错误消息)时如何自动布局约束 - How do I auto layout constraints when I add a new view such as a error message to the top of a main view 如何解决带有约束的自动布局“难题”? - How do I solve this Auto Layout “puzzle” with constraints? 如何为具有自动布局约束的UILabel移动设置动画? - How do I animate the move a UILabel with auto layout constraints? 如何为自动布局锚点约束添加标识符? - How do I add an identifier to auto layout anchor constraints? 故事板:当我更改布局约束时,如何让Xcode自动更新帧? - Storyboard: How do I let Xcode automatically update frames when I change layout constraints? 如何为我的视图解决自动布局约束 - How to resolve auto layout constraints for my view 使用自动布局,如何根据图像动态调整 UIImageView 的大小? - With Auto Layout, how do I make a UIImageView's size dynamic depending on the image? 自动布局:当某些视图为空时自动更新约束 - Auto layout: auto update constraints when some view is empty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM