CellMucChupWithDelete.swift
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
}
}