对于我的 UITableView 之一,要允许更多文本或大字体文本适合字段,我需要添加或调整字体大小。
我对 adjustsFontSizeToFitWidth 使用了 bool 值。并且 clipsToBounds=true。但这并不总是对我有用,不确定为什么会不一致,尤其是当您要包含更大字体的文本时。有什么更正吗?
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
let headerLabel = UILabel(frame: CGRect(x: 40, y: 0, width:
tableView.bounds.size.width, height: tableView.bounds.size.height))
headerLabel.textColor = UIColor.white
headerLabel.text = self.tableView(self.tableView, titleForHeaderInSection: section)
headerLabel.sizeToFit()
headerLabel.adjustsFontSizeToFitWidth = true
headerLabel.clipsToBounds=true
headerLabel.numberOfLines=0
headerLabel.lineBreakMode = NSLineBreakMode.byTruncatingTail
headerLabel.minimumScaleFactor = 0.2
headerView.addSubview(headerLabel)
return headerView
}
最佳答案
删除以下可能是?
headerLabel.sizeToFit()
这将允许
adjustsFontSizeToFitWidth
属性(property)运作。
关于ios - 自动调整 UITableView 的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51504747/