ios - sectionHeader 中的自动调整字体大小

标签 ios swift uitableview tableview uitableviewsectionheader

我想在我的 Tableview 的 sectionHeader 中显示名称和其他一些简短信息。

有些名称非常大,所以放不下,有没有办法像在标签中那样自动调整 sectionHeader 中的字体大小:

label.adjustsFontSizeToFitWidth = true;

最佳答案

最简单的方法是在 tableView(_:viewForHeaderInSection:)

中创建一个 UILabel

Apple Docu 讨论:

The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView(_:viewForHeaderInSection:) instead.

关于ios - sectionHeader 中的自动调整字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51401926/

相关文章:

ios - 如何将 iOS 应用程序从一个开发者帐户转移到另一个开发者帐户?

iphone - iPhone 关机时是否可以引发事件?

ios - 在没有预处理器宏的情况下,有没有办法在 Xcode 项目的项目级别定义实用的方案特定标志

IOS Swift Post 请求返回一些不清楚的内容

ios - UITableViewCell 单元重用和 UILabel 自动布局动态调整大小

ios - 获取表格左侧的宽度?

ios - 无法将类型 'UITableViewCell' 的值转换为指定类型

iphone - 克隆现有的球 Sprite 和 box2d cocos2d 中的对象

ios - Swift - 文本字段不适合 Canvas

swift - 如何将 UICollectionViewCell 的背景图像获取到旋转时的单元格的spectFit?