小编Dar*_*śla的帖子

UITableViewCell动态高度不适用于大小类

设置estimatedRowHeight和rowHeight的UITableView使表视图计算每个细胞的适当的高度.在我使用大小类之前,它就像一个魅力.看起来所有的计算都是针对Any/Any size类进行的,稍后会应用更大的字体.结果,没有正确计算单元的高度并且标签不适合.

这是我的代码:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.estimatedRowHeight = 50
        self.tableView.rowHeight = UITableViewAutomaticDimension
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Reuse", forIndexPath: indexPath) as! MyTableViewCell
        println("Label font size: \(cell.myLabel.font)") // it prints (...)font-size: 11.00pt for all the size classes
        return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

布局看起来像这样: …

uitableview ios size-classes

9
推荐指数
1
解决办法
1069
查看次数

标签 统计

ios ×1

size-classes ×1

uitableview ×1