字体大小更改部分页脚 table 视图
Font size change section footer table view
我目前正在 Swift 中构建一个 iOS 应用程序,但我遇到了一些问题。我的设置视图是一个 tableviewcontroller。是成群结队的。我的Table视图是动态的,字体是动态的。
我想在设置应用程序中对字体大小的更改进行交互。
如果我的应用程序已经是 运行,字体大小会改变,但布局会被破坏。 (从最小字体到最大字体)
图片:Layout bug
如果我用新的字体设置重新启动我的应用程序,没有问题...
这是一个 XCODE project example,你会看到这个错误。
你能帮我找到解决办法吗?谢谢
更改字体大小后尝试调用
self.view.setNeedsLayout()
它在 UIView 中设置一个标志,将其标记为需要更改布局。
你也可以尝试拨打
self.view.layoutIfNeeded()
Apple 文档说:
Use this method to force the layout of subviews before drawing. Using the view that receives the message as the root view, this method lays out the view subtree starting at the root.
希望对你有帮助
UIContentSizeCategoryDidChangeNotification
就是您要找的。
根据文档:
Posted when the user changes the preferred content size setting.
This notification is sent when the value in the
preferredContentSizeCategory property changes. The userInfo dictionary
of the notification contains the UIContentSizeCategoryNewValueKey key,
which reflects the new setting.
回调实现示例:
func handleContentSizeCategoryDidChangeNotification(notification: NSNotification) {
self.questionLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
}
最后,我发现这是一个 iOS 错误。我在 Apple Apps 中发现了同样的错误。
当您设置最小字体,退出应用程序并设置最大字体时,会出现该错误。
感谢您的帮助。
我目前正在 Swift 中构建一个 iOS 应用程序,但我遇到了一些问题。我的设置视图是一个 tableviewcontroller。是成群结队的。我的Table视图是动态的,字体是动态的。
我想在设置应用程序中对字体大小的更改进行交互。
如果我的应用程序已经是 运行,字体大小会改变,但布局会被破坏。 (从最小字体到最大字体)
图片:Layout bug
如果我用新的字体设置重新启动我的应用程序,没有问题...
这是一个 XCODE project example,你会看到这个错误。
你能帮我找到解决办法吗?谢谢
更改字体大小后尝试调用
self.view.setNeedsLayout()
它在 UIView 中设置一个标志,将其标记为需要更改布局。
你也可以尝试拨打
self.view.layoutIfNeeded()
Apple 文档说:
Use this method to force the layout of subviews before drawing. Using the view that receives the message as the root view, this method lays out the view subtree starting at the root.
希望对你有帮助
UIContentSizeCategoryDidChangeNotification
就是您要找的。
根据文档:
Posted when the user changes the preferred content size setting.
This notification is sent when the value in the preferredContentSizeCategory property changes. The userInfo dictionary of the notification contains the UIContentSizeCategoryNewValueKey key, which reflects the new setting.
回调实现示例:
func handleContentSizeCategoryDidChangeNotification(notification: NSNotification) {
self.questionLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
}
最后,我发现这是一个 iOS 错误。我在 Apple Apps 中发现了同样的错误。
当您设置最小字体,退出应用程序并设置最大字体时,会出现该错误。
感谢您的帮助。