gpt4 book ai didi

ios - adjustsFontForContentSizeCategory iOS 的替代方案是什么?

转载 作者:可可西里 更新时间:2023-11-01 00:40:11 24 4
gpt4 key购买 nike

此属性仅适用于 iOS 10+ 操作系统什么是替换属性的替代解决方案。

Apple documentation for Objective C

  @property(nonatomic) BOOL adjustsFontForContentSizeCategory;

Apple documentation for Swift

var adjustsFontForContentSizeCategory: Bool { get set }

当我们在低版本应用程序中打开时崩溃时,此属性在低版本中不起作用。

最佳答案

在较低版本中,没有定义的属性,您必须以编程方式处理它,您必须监听字体更改的系统通知 - UIContentSizeCategoryDidChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangePreferredContentSize:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];

快速版本

NotificationCenter.default.addObserver(self, selector: 
#selector(self.didChangePreferredContentSize), name:
UIContentSizeCategoryDidChangeNotification, object: nil)

然后您可以在选择器方法 - didChangePreferredContentSize 中处理您的要求。

最佳实践指南 - 一旦离开 View Controller ,请记住移除观察者。

关于ios - adjustsFontForContentSizeCategory iOS 的替代方案是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45094802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com