Это мой код. и я просто хочу провести границу между клетками. как календарь. но я не знаю как это сделать .. не могли бы вы мне помочь?
class ViewController: UIViewController{
var selectedRow : Int?
let data = [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]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.dataSource = self
self.collectionView.backgroundColor = .black
self.collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier : "MyCell")
}}
extension ViewController : UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return data.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as! CollectionViewCell
cell.button.tag = indexPath.item
// 나를 살린부분.. ㄷㄷ
cell.button.addTarget(self, action:#selector(buttonPressed(_:)) , for: .touchUpInside)
cell.Label.text = String(data[indexPath.row])
if selectedRow == indexPath.item{
cell.Label.textColor = .white
cell.Label2.backgroundColor = .red
cell.Label2.layer.cornerRadius = 0.5 * cell.Label2.bounds.size.width
cell.Label2.clipsToBounds = true
}else{
cell.Label.textColor = .black
cell.Label2.backgroundColor = .white
cell.Label2.layer.cornerRadius = 0
}
return cell
}
@IBAction func buttonPressed(_ sender: UIButton) {
if selectedRow == sender.tag{
selectedRow = nil
}else{
selectedRow = sender.tag
}
self.collectionView.reloadData()
}
}