【问题标题】:UITableView estimatedRowheight Dynamic TypeUITableView 估计行高动态类型
【发布时间】:2016-12-28 20:04:04
【问题描述】:

我正在使用自动调整大小的表格视图单元格来支持动态类型。

当用户将其字体大小设置为正常时,行高为 44。但是,当用户将其字体调整为更小或更大时,行高分别减小或增加。

那么,我应该将estimatedRowHeight 设置为什么,因为rowHeight 会根据用户的动态类型设置而变化?

【问题讨论】:

  • 这只是一个估计,以加快计算。你不需要精确。设置为 44 就可以了
  • 我知道我不需要精确,因为这只是一个估计,但我仍然希望准确。 Auto Layout Guide: Working with Self-Sizing Table View Cells 说,“尽量让估计的行高尽可能准确。系统根据这些估计计算滚动条高度等项目。估计越准确,用户体验就越无缝。”跨度>

标签: ios uitableview row-height


【解决方案1】:

When the default Dynamic Type is chosen the .body pointSize is 17.0, so I use this calculation

self.tableView.estimatedRowHeight = [yourEstimateForDefaultSize] / 17.0 * UIFont.preferredFont(forTextStyle: .body).pointSize

对于默认的动态类型大小,此估计值是准确的。对于其他尺寸,它会失去准确性,但它是一种改进

【讨论】:

    【解决方案2】:

    我可能会尝试使用委托方法动态估计高度:

    func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
        return topOffset + bottomOffset + fontSize * countOfLines
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 2012-09-08
      • 1970-01-01
      • 2016-07-14
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      相关资源
      最近更新 更多