block-employee-directory/EmployeeDirectory/Views/EmployeeTableViewCell.swift
Matt Bruce 09c8a1ef5a first cut of EmployeeTableViewCell
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
2025-01-20 18:46:23 -06:00

84 lines
3.1 KiB
Swift

//
// EmployeeTableViewCell.swift
// EmployeeDirectory
//
// Created by Matt Bruce on 1/20/25.
//
import UIKit
public class EmployeeTableViewCell: UITableViewCell {
static let identifier = "EmployeeTableViewCell"
private let photoImageView = UIImageView()
private let nameLabel = UILabel()
private let emailLabel = UILabel()
private let stackView = UIStackView()
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
// Configure photoImageView
photoImageView.contentMode = .scaleAspectFill
photoImageView.clipsToBounds = true
photoImageView.layer.cornerRadius = 25
photoImageView.translatesAutoresizingMaskIntoConstraints = false
photoImageView.image = UIImage(systemName: "person.crop.circle")
// Configure labels with text styles
nameLabel.font = UIFont.preferredFont(forTextStyle: .headline) // Bold, prominent text
nameLabel.adjustsFontForContentSizeCategory = true // Adapts to Dynamic Type
emailLabel.font = UIFont.preferredFont(forTextStyle: .body)
emailLabel.textColor = .blue
emailLabel.adjustsFontForContentSizeCategory = true // Adapts to Dynamic Type
// Configure stackView
stackView.axis = .vertical
stackView.spacing = 5
stackView.translatesAutoresizingMaskIntoConstraints = false
// Add labels to stackView
stackView.addArrangedSubview(nameLabel)
stackView.addArrangedSubview(emailLabel)
// Add subviews
contentView.addSubview(photoImageView)
contentView.addSubview(stackView)
// Add constraints
NSLayoutConstraint.activate([
photoImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),
photoImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
photoImageView.widthAnchor.constraint(equalToConstant: 50),
photoImageView.heightAnchor.constraint(equalToConstant: 50),
stackView.leadingAnchor.constraint(equalTo: photoImageView.trailingAnchor, constant: 10),
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -10),
stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10),
stackView.bottomAnchor.constraint(lessThanOrEqualTo: contentView.bottomAnchor, constant: -10)
])
}
public override func prepareForReuse() {
super.prepareForReuse()
photoImageView.image = UIImage(systemName: "person.crop.circle")
nameLabel.text = nil
emailLabel.text = nil
}
public func configure(with model: Employee) {
// Bind data to UI components
nameLabel.text = model.fullName
emailLabel.text = model.emailAddress
}
}