Ios 自动调整UITableView的字体大小
对于我的UITableView之一,要允许更多文本或大字体文本适合字段,我需要添加或调整字体大小 我对adjustsFontSizeToFitWidth使用了布尔值。clipsToBounds=true。但这并不总是适用于我,我不知道为什么它是不一致的,特别是当你有更大的字体大小的文本要包括在内。有什么更正吗Ios 自动调整UITableView的字体大小,ios,swift,uitableview,Ios,Swift,Uitableview,对于我的UITableView之一,要允许更多文本或大字体文本适合字段,我需要添加或调整字体大小 我对adjustsFontSizeToFitWidth使用了布尔值。clipsToBounds=true。但这并不总是适用于我,我不知道为什么它是不一致的,特别是当你有更大的字体大小的文本要包括在内。有什么更正吗 override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> U
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
物业运作。你到底有什么问题?您是否阅读了文档,问题在于您只调整了一次标签的大小(顺便说一句,太快了),仅此而已。因此字体永远不会调整,因为标签的大小永远不会改变。创建一个标签并在界面生成器中查看效果可能更容易Hanks zombie和rmaddy!您还应该向标签添加约束,使其与标题视图一起调整大小。您应该添加问题以演示问题。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if searching {
cell?.textLabel?.text = searchedLabour[indexPath.row]
cell?.textLabel?.sizeToFit()
cell?.textLabel?.adjustsFontSizeToFitWidth = true
cell?.textLabel?.numberOfLines = 2
cell?.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail
} else {
cell?.textLabel?.text = labourWordsArray[indexPath.row]
cell?.textLabel?.sizeToFit()
cell?.textLabel?.adjustsFontSizeToFitWidth = true
cell?.textLabel?.numberOfLines = 2
cell?.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail
}
return cell!
}