Advertisement
Don_Mag

Untitled

Aug 25th, 2023
1,843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.86 KB | None | 0 0
  1. class OldRecordsTableViewCell: UITableViewCell {
  2.     static let identifier: String = "c"
  3. }
  4.  
  5. class RecordingViewController: UIViewController {
  6.    
  7.     private let tableView: UITableView = {
  8.         let tableView = UITableView()
  9.         tableView.translatesAutoresizingMaskIntoConstraints = false
  10.         tableView.register(OldRecordsTableViewCell.self, forCellReuseIdentifier: OldRecordsTableViewCell.identifier)
  11.         tableView.separatorStyle = .none
  12.         tableView.backgroundColor = .clear
  13.         tableView.isScrollEnabled = true
  14.         return tableView
  15.     }()
  16.    
  17.     let allRecordsLabel = UILabel()
  18.     let contentView1 = UIView()
  19.    
  20.     override func viewDidLoad() {
  21.         super.viewDidLoad()
  22.  
  23.         allRecordsLabel.translatesAutoresizingMaskIntoConstraints = false
  24.         contentView1.translatesAutoresizingMaskIntoConstraints = false
  25.        
  26.         view.addSubview(contentView1)
  27.         contentView1.addSubview(allRecordsLabel)
  28.         contentView1.addSubview(tableView)
  29.        
  30.         NSLayoutConstraint.activate([
  31.             contentView1.topAnchor.constraint(equalTo: view.topAnchor),
  32.             contentView1.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  33.             contentView1.trailingAnchor.constraint(equalTo: view.trailingAnchor),
  34.             contentView1.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  35.            
  36.             allRecordsLabel.topAnchor.constraint(equalTo: contentView1.topAnchor, constant: 80.0),
  37.             allRecordsLabel.leadingAnchor.constraint(equalTo: contentView1.leadingAnchor),
  38.             allRecordsLabel.trailingAnchor.constraint(equalTo: contentView1.trailingAnchor),
  39.  
  40.             tableView.topAnchor.constraint(equalTo: allRecordsLabel.bottomAnchor, constant: 26.5),
  41.             tableView.bottomAnchor.constraint(equalTo: contentView1.bottomAnchor, constant: -15),
  42.             tableView.leadingAnchor.constraint(equalTo: contentView1.leadingAnchor, constant: 43),
  43.             tableView.trailingAnchor.constraint(equalTo: contentView1.trailingAnchor, constant: -43)
  44.         ])
  45.  
  46.         allRecordsLabel.text = "All Records"
  47.        
  48.         view.backgroundColor = .systemYellow
  49.         contentView1.backgroundColor = .systemBlue
  50.         allRecordsLabel.backgroundColor = .green
  51.        
  52.         tableView.dataSource = self
  53.         tableView.delegate = self
  54.        
  55.     }
  56.  
  57.    
  58. }
  59.  
  60. extension RecordingViewController: UITableViewDataSource, UITableViewDelegate {
  61.    
  62.     func numberOfSections(in tableView: UITableView) -> Int {
  63.         return 1
  64.     }
  65.    
  66.     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  67.         return 20
  68.     }
  69.    
  70.     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  71.         let cell = tableView.dequeueReusableCell(withIdentifier: OldRecordsTableViewCell.identifier, for: indexPath) as! OldRecordsTableViewCell
  72.         cell.textLabel?.text = "Text \(indexPath.row)"
  73.         return cell
  74.     }
  75.    
  76.     func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  77.        
  78.         print("Content Size: \(tableView.contentSize)")
  79.         print("Bounds Size: \(tableView.bounds.size)")
  80.        
  81.         return true
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement