Dar*_*śla 9 uitableview ios size-classes
设置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)
现在,当我在iPhone上打开应用程序时,一切看起来都像预期的那样.但是在iPad上,单元格没有正确调整大小.事实上,如果字体大小为11pt而不是40pt,它们会调整大小以适应文本.
问题是:如何在应用大小类后强制执行计算?
我已经尝试过覆盖特征收集的技巧,如下所述:https://stackoverflow.com/a/28514006但它不起作用.我的意思是,大小类已正确读取(常规/常规)但字体大小仍为11pt.
您可以从Github下载这个简单的项目:https://github.com/darecki/TableViewTest
截图:
tableView.reloadData(): 编辑:格式化,添加Github链接.
Rob*_*egg -3
在 Interface Builder -> Size Inspector 中设置标签上的首选最大宽度。这为我解决了这个问题。还要确保行数为 0。
| 归档时间: |
|
| 查看次数: |
1069 次 |
| 最近记录: |