SWIFT Table Cell xibの使用


settingTableView.delegate = self
settingTableView.dataSource = self

//cell xib 가져오기
let pronib = UINib(nibName: "ProfileCell", bundle:nil)//nib를 가져옴 xib를 바이너리화 한게 nib

 //table view에 cell 가져올 때 사용
        settingTableView.register(pronib, forCellReuseIdentifier: "ProfileCell")

extension ViewController: UITableViewDelegate, UITableViewDataSource 
{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
       let cell = tableView.dequeueReusableCell
            (withIdentifier: "ProfileCell", for: indexPath) as! ProfileCell

  return cell
}

                           
  • ProfileCell.swift
  • import UIKit
    
    class ProfileCell: UITableViewCell {
    
        @IBOutlet weak var profileImageView: UIImageView!
        
        @IBOutlet weak var topTitle: UILabel!
        
        @IBOutlet weak var bottomDescription: UILabel!
        
        //기본 세팅을 여기서 많이한다
        override func awakeFromNib() {
            super.awakeFromNib()
            
            let profileHeight:CGFloat = 60
            // Initialization code
            profileImageView.layer.cornerRadius = profileHeight / 2
            
            topTitle.textColor = .blue
            topTitle.font = UIFont.systemFont(ofSize: 20)
            
            bottomDescription.textColor = .darkGray
            bottomDescription.font = UIFont.systemFont(ofSize: 16
            )
        }
    
        override func setSelected(_ selected: Bool, animated: Bool) {
            super.setSelected(selected, animated: animated)
    
            // Configure the view for the selected state
        }
        
    }