@@ -9,64 +9,73 @@ import TLPhotoPicker
99import UIKit
1010
1111protocol PreviewFooterViewDelegate : AnyObject {
12- func footerView( _ headerView: PreviewFooterView , didPressSelectButton button: UIButton )
12+ func footerView( _ headerView: PreviewFooterView , didPressSelectButton button: SelectButton )
1313}
1414
15- class PreviewFooterView : TLPhotoCollectionViewCell {
16- weak var viewDelegate : PreviewFooterViewDelegate ?
17-
18- lazy var selectButton : UIButton = {
19- let button = UIButton ( type: . system)
15+ class SelectButton : UIButton {
16+ override init ( frame: CGRect ) {
17+ super. init ( frame: frame)
2018
21- button. addTarget ( self , action: #selector( PreviewFooterView . selectAction ( button: ) ) , for: . touchUpInside)
22- button. frame = CGRect ( x: 0 , y: 0 , width: 24 , height: 24 )
23- //
24- // button.layer.cornerRadius = 12
25- // button.clipsToBounds = true
19+ self . frame. size = . init( width: 24 , height: 24 )
2620
27- button . backgroundColor = config . selectedColor
21+ backgroundColor = . clear
2822
29- button . layer. borderWidth = 1.5
30- button . layer. borderColor = UIColor . white. cgColor
23+ layer. borderWidth = 2
24+ layer. borderColor = UIColor . white. cgColor
3125
32- button . layer. cornerRadius = 16
33- button . clipsToBounds = true
34- button . contentEdgeInsets = UIEdgeInsets ( top: 8 , left: 8 , bottom: 8 , right: 8 )
26+ layer. cornerRadius = 16
27+ clipsToBounds = true
28+ contentEdgeInsets = UIEdgeInsets ( top: 4 , left: 4 , bottom: 4 , right: 4 )
3529
36- button . setTitle ( " 1 " , for: . normal)
37- button . setTitleColor ( . white , for : . normal )
30+ setTitleColor ( . white , for: . normal)
31+ titleLabel ? . font = . boldSystemFont ( ofSize : 16 )
3832
39- button. translatesAutoresizingMaskIntoConstraints = false
33+ translatesAutoresizingMaskIntoConstraints = false
34+ }
4035
41- // Tạo constraints để cố định vị trí của tiêu đề ở giữa tuyệt đối (absolute center)
36+ @objc open var selectedAsset : Bool = false {
37+ willSet( newValue) {
38+ backgroundColor = config. selectedColor
39+ if !newValue {
40+ backgroundColor = . clear
41+ setTitle ( " " , for: . normal)
42+ }
43+ }
44+ }
4245
43- // let label = UILabel()
44- // label.text = "2"
45- // label.textColor = UIColor.white // Tuỳ chỉnh màu văn bản theo ý muốn
46- // label.textAlignment = .center
47- // label.frame = button.bounds // Đặt kích thước và vị trí của UILabel bằng bằng với UIButton
48- // button.addSubview(label)
46+ @available ( * , unavailable)
47+ required init ? ( coder _: NSCoder ) {
48+ fatalError ( " init(coder:) has not been implemented " )
49+ }
50+ }
4951
50- return button
51- } ( )
52+ class PreviewFooterView : UIView {
53+ weak var viewDelegate : PreviewFooterViewDelegate ?
54+ var selectButton : SelectButton !
5255
5356 override init ( frame: CGRect ) {
5457 super. init ( frame: frame)
58+
5559 let stackView = UIStackView ( )
60+
61+ selectButton = SelectButton ( )
62+
63+ selectButton. addTarget ( self , action: #selector( PreviewFooterView . selectAction ( button: ) ) , for: . touchUpInside)
64+
5665 stackView. translatesAutoresizingMaskIntoConstraints = false
5766 stackView. axis = . horizontal
5867 stackView. alignment = . trailing
5968 addSubview ( stackView)
6069
61- self . selectButton. translatesAutoresizingMaskIntoConstraints = false
62- stackView. addArrangedSubview ( self . selectButton)
70+ selectButton. translatesAutoresizingMaskIntoConstraints = false
71+ stackView. addArrangedSubview ( selectButton)
6372
64- self . selectButton. centerXAnchor. constraint ( equalTo: stackView. centerXAnchor) . isActive = true
65- self . selectButton. centerYAnchor. constraint ( equalTo: stackView. centerYAnchor) . isActive = true
73+ selectButton. centerXAnchor. constraint ( equalTo: stackView. centerXAnchor) . isActive = true
74+ selectButton. centerYAnchor. constraint ( equalTo: stackView. centerYAnchor) . isActive = true
6675
6776 // (Tuỳ chọn) Đặt constraints cho chiều rộng và chiều cao của UIButton
68- self . selectButton. widthAnchor. constraint ( equalToConstant: 32 ) . isActive = true
69- self . selectButton. heightAnchor. constraint ( equalToConstant: 32 ) . isActive = true
77+ selectButton. widthAnchor. constraint ( equalToConstant: 32 ) . isActive = true
78+ selectButton. heightAnchor. constraint ( equalToConstant: 32 ) . isActive = true
7079
7180 NSLayoutConstraint . activate ( [
7281 stackView. trailingAnchor. constraint ( equalTo: trailingAnchor, constant: - 20 ) ,
@@ -82,7 +91,7 @@ class PreviewFooterView: TLPhotoCollectionViewCell {
8291 super. layoutSubviews ( )
8392 }
8493
85- @objc func selectAction( button: UIButton ) {
86- self . viewDelegate? . footerView ( self , didPressSelectButton: button)
94+ @objc func selectAction( button: SelectButton ) {
95+ viewDelegate? . footerView ( self , didPressSelectButton: button)
8796 }
8897}
0 commit comments