代码之家  ›  专栏  ›  技术社区  ›  john doe

自动调整iOS 11中不工作的单元格大小

  •  1
  • john doe  · 技术社区  · 8 年前

    enter image description here

    结果如下:

    enter image description here

    3 回复  |  直到 8 年前
        1
  •  3
  •   Glenn Posadas    8 年前

    UITableViewCell ,设置 rowHeight estimatedRowHeight 你的 UITableView viewDidLoad() 方法,如下所示:

    self.tableView.estimatedRowHeight = 150.0
    self.tableView.rowHeight = UITableViewAutomaticDimension
    

    然后如果你想或需要实施 heightForRow UITableViewDelegate UITableViewAutomaticDimension 不管怎样 row section 这需要一个自动调整大小的单元格,如下所示:

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let section = indexPath.section
        if let itemSection = ItemTableViewSections(rawValue: section) {
            switch itemSection {
            case .header: return 80.0
            case .photos: return 95.0
            case .note: return UITableViewAutomaticDimension
            case .rejectOptions: return 50.0
            }
        }
    
        return 0
    }
    

    最后,如果答案真的像上一个问题一样回答了您的问题,请不要忘记选择答案:)

    只是别忘了设置标签的约束 -顶部、底部、前导和尾随。自动调整单元格大小需要这些约束。最后,设置 UILabel 的行数为0。

    enter image description here

        2
  •  1
  •   Jokar Babu    8 年前

    增长 垂直内容拥抱优先级 通过 UILabel的

        3
  •  0
  •   Dennis Lau    8 年前