class TransactionCell: UITableViewCell {
}
class TransactionsHeaderView: UITableViewHeaderFooterView {
static let reuseId = "CustomHeader"
}
class TransactionsViewController: UIViewController {
let cellId = "cellID"
let numSections: Int = 4
lazy var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
commonInit()
}
private func commonInit() {
//view.backgroundColor = .clear
tableView.backgroundColor = .systemBackground
tableView.rowHeight = 74
tableView.sectionHeaderHeight = 50
tableView.register(TransactionCell.self, forCellReuseIdentifier: cellId)
tableView.register(TransactionsHeaderView.self, forHeaderFooterViewReuseIdentifier: TransactionsHeaderView.reuseId)
tableView.delegate = self
tableView.dataSource = self
tableView.contentInsetAdjustmentBehavior = .never
tableView.separatorInset = UIEdgeInsets(top: 0, left: 32, bottom: 0, right: 16)
tableView.tableFooterView = UIView()
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
let g = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: g.topAnchor, constant: 20.0),
tableView.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
tableView.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -20.0),
tableView.bottomAnchor.constraint(equalTo: g.bottomAnchor, constant: -20.0),
])
}
}
extension TransactionsViewController: UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return numSections // self.sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4 //sections[section].transactions.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as? TransactionCell else {
fatalError("The dequeued cell is not an instance of HomeTableViewCell.")
}
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
print(#function, section)
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: TransactionsHeaderView.reuseId) as! TransactionsHeaderView
header.contentView.backgroundColor = .orange
return header
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
print(#function, section)
return 50
}
}
Comments
0 B
|👍
/👎