import Foundation import UIKit import GeneralUtils class CellMucChupWithDelete: BaseTableViewCellUI { var tvTitle: UILabel!, btnDelete: UIImageView! var mucChup: ShootItem! static func registerClass(tableView: UITableView, forCellReuseIdentifier: String) { tableView.register(CellMucChupWithDelete.self, forCellReuseIdentifier: forCellReuseIdentifier) } override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) initView() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) initView() } private func initView() { let stackView = UIStackView() stackView.axis = UILayoutConstraintAxis.horizontal stackView.spacing = 8 stackView.translatesAutoresizingMaskIntoConstraints = false self.contentView.addSubview(stackView) NSLayoutConstraint.activate([stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), stackView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 8), stackView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -8), stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -8)]) tvTitle = UILabel() tvTitle.numberOfLines = 0 stackView.addArrangedSubview(tvTitle) btnDelete = UIImageView() btnDelete.contentMode = .scaleAspectFit btnDelete.isUserInteractionEnabled = true stackView.addArrangedSubview(btnDelete) btnDelete.widthAnchor.constraint(equalToConstant: 30).isActive = true btnDelete.image = #imageLiteral(resourceName:"delete_ic") let tap = UITapGestureRecognizer(target: self, action: #selector(CellMucChupWithDelete.btnDeleteClick)) btnDelete.addGestureRecognizer(tap) } func btnDeleteClick() { if let vcNhapMucChup = self.viewController as? VCNhapMucChup { vcNhapMucChup.deleteMucChup(mucChup) } } override func configCellWithData(baseObj: Any, index: Int) { super.configCellWithData(baseObj: baseObj, index: index) mucChup = baseObj as! ShootItem tvTitle.text = mucChup.name } }