Skip to content

Instantly share code, notes, and snippets.

@kmuralidharan91
Created October 14, 2020 04:32
Show Gist options
  • Save kmuralidharan91/f7ef3328de399d9a3a8daedda2dd074a to your computer and use it in GitHub Desktop.
Save kmuralidharan91/f7ef3328de399d9a3a8daedda2dd074a to your computer and use it in GitHub Desktop.
import UIKit
final class CustomTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
commonInit()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private let containerView = UIStackView()
private let cellView = CustomTableCellView()
private let detailView = CustomTableDetailView()
func setUI(with index: Int) {
cellView.setUI(with: Constants.fruits[index])
detailView.setUI(with: index, image: UIImage(named: Constants.fruits[index]) ?? UIImage())
}
func commonInit() {
selectionStyle = .none
detailView.isHidden = true
containerView.axis = .vertical
contentView.addSubview(containerView)
containerView.addArrangedSubview(cellView)
containerView.addArrangedSubview(detailView)
containerView.translatesAutoresizingMaskIntoConstraints = false
cellView.translatesAutoresizingMaskIntoConstraints = false
detailView.translatesAutoresizingMaskIntoConstraints = false
containerView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor).isActive = true
containerView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor).isActive = true
containerView.topAnchor.constraint(equalTo: self.contentView.topAnchor).isActive = true
containerView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment