For a tableView: I try to change my code from using cell.textLabel to cell.contentConfiguration, we can't get the same result as before (using cell.textLabel), I like to keep the row heigh at 20, the old code display nicely, but the new code won't be able to show it at all unless I use row height 40. Here's the code:
import UIKit
var fruites = ["Apple","Orange","PineApple", "Water Melon", "Banana"]
class ViewController: UIViewController {
@IBOutlet weak var tblTableViewA: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tblTableViewA.dataSource = self
tblTableViewA.delegate = self
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fruites.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellA", for: indexPath)
let fruit = fruites[indexPath.row]
// New code does not display right, content does not display properly like old code. when row height = 20, it won't even show.
/*
var content = cell.defaultContentConfiguration()
content.textProperties.adjustsFontSizeToFitWidth = true
content.text = fruit
cell.contentConfiguration = content
*/
// Old code works perfect
cell.textLabel?.adjustsFontSizeToFitWidth = true
cell.textLabel!.text = fruit
return cell
}
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return 20 //CGFloat(20)
}
}
Thanks in advance!