NFCCardVC.swift
5.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// NFCCardVC.swift
// Twear
//
// Created by yangbin on 2022/2/12.
//
import UIKit
import SnapKit
class NFCCardVC: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var collectionViewFlowLayout: UICollectionViewFlowLayout!
private let cardArray1 = ["NFC_1", "NFC_2", "NFC_3", "NFC_4", "NFC_5", "NFC_6"]
private let cardArray2 = ["NFC_7", "NFC_8", "NFC_9", "NFC_10", "NFC_11", "NFC_12"]
private let textArray = [LocString("色彩卡片"), LocString("创意卡片")]
var cardClosure: ((_ card: String) -> ())?
var curIndexPath: IndexPath = IndexPath(row: 0, section: 0)
override func viewDidLoad() {
super.viewDidLoad()
title = LocString("显示")
let saveButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
saveButton.setTitle(LocString("保存"), for: .normal)
saveButton.titleLabel?.font = RegularFont(14)
saveButton.setTitleColor(TintColor, for: .normal)
saveButton.addTarget(self, action: #selector(save), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: saveButton)
collectionViewFlowLayout.minimumLineSpacing = 10
collectionViewFlowLayout.minimumInteritemSpacing = 10
collectionViewFlowLayout.sectionInset = UIEdgeInsets(top: 10, left: 12, bottom: 5, right: 12)
let width = (SCREEN_WIDTH-36)/2.0
collectionViewFlowLayout.itemSize = CGSize(width: width, height: width*3.0/7.0)
collectionViewFlowLayout.headerReferenceSize = CGSize(width: SCREEN_WIDTH, height: 30)
// collectionView.bounces = false
collectionView.showsVerticalScrollIndicator = false
// Do any additional setup after loading the view.
}
@objc private func save() {
cardClosure?("\(curIndexPath.section*6+curIndexPath.row+1)")
navigationController?.popViewController(animated: true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
extension NFCCardVC: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
var reusableView: UICollectionReusableView?
if kind == UICollectionView.elementKindSectionHeader {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "NFCCardHeaderView", for: indexPath) as! NFCCardHeaderView
let label = UILabel()
label.font = RegularFont(11)
// label.text = LocString(settingArray[section])
headerView.addSubview(label)
label.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.bottom.equalToSuperview().offset(-2)
}
label.text = textArray[indexPath.section]
// headerView.backgroundColor = .red
reusableView = headerView
// return headerV
}
return reusableView!
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// if section == 0 {
// return 1
// } else {
return 6
// }
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NFCCardCell", for: indexPath) as! NFCCardCell
if indexPath.section == 0 {
cell.imageView.image = UIImage(named: cardArray1[indexPath.row])
} else {
cell.imageView.image = UIImage(named: cardArray2[indexPath.row])
}
if indexPath == curIndexPath {
cell.selectedImageView.isHidden = false
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! NFCCardCell
let tempCell = collectionView.cellForItem(at: curIndexPath) as! NFCCardCell
tempCell.selectedImageView.isHidden = true
cell.selectedImageView.isHidden = false
curIndexPath = indexPath
}
}
class NFCCardHeaderView: UICollectionReusableView {
// var label: UILabel = UILabel()
//
// override init(frame: CGRect) {
// super.init(frame: frame)
// self.backgroundColor = .black
// label.font = RegularFont(11)
//// label.text = LocString(settingArray[section])
// self.addSubview(label)
// label.snp.makeConstraints { make in
// make.left.equalToSuperview().offset(12)
// make.top.equalToSuperview().offset(7.5)
// }
// }
//
// required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
}