I am developing in IOS and I am a first-timer.
The idea is that when I started the program I made a collection View of buttons in the following way:
@IBOutlet weak var collectionView: UICollectionView!
let taille = 45
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return taille
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let identifier = "item"
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! CollectionViewCell
cell.btnCollection.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
return cell
}
@objc func buttonAction(sender: UIButton!) {
sender.backgroundColor = UIColor.red
sender.description =
}
So far I only paint the button that I click on, what I want to know is whether there is the possibility of recovering the position within the button collection that I click
If it exists, what function to use?