
У меня есть собственный CollectionViewCell с функцией установки title, description and image
, но я не могу понять, как установить его, когда выбрано 1 cell
, а секунда - нет , Я использую этот код. Я нахожу центр collectionView
и получаю array
моего indexPath.item
[0,1], но я могу получить доступ к своей камере
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let centerPoint = CGPoint(x: self.collectionView.center.x, //+ self.collectionView.contentOffset.x,
y: self.collectionView.center.y) //+ self.collectionView.contentOffset.y)
let collectionViewCenterPoint = self.view.convert(centerPoint, to: collectionView)
for cell in collectionView.visibleCells {
let indexPath = collectionView.indexPathForItem(at: collectionViewCenterPoint)
switch indexPath?.item {
case 0:
break
case 1:
break
case .none:
break
case .some(_):
break
}
}
}
это моя камера
class RoleCollectionViewCell: UICollectionViewCell, NiBLoadable {
@IBOutlet weak var circleView: UIView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var roleLabel: UILabel!
@IBOutlet weak var descriptionTextView: UITextView!
override func awakeFromNib() {
super.awakeFromNib()
Decorator.decorate(self)
}
func setActive(image: UIImage, borderColor: CGColor) {
circleView.layer.borderColor = borderColor
imageView.image = image
}
func setTitle(text: String) {
roleLabel.text = text
}
func setDescription(text: String) {
descriptionTextView.text = text
}
}
и это мой метод возврата ячеек
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let centerPoint = CGPoint(x: self.collectionView.center.x, y: self.collectionView.center.y)
let collectionViewCenterPoint = self.view.convert(centerPoint, to: collectionView)
let models = model[indexPath.row]
switch models {
case .client:
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: RoleCollectionViewCell.name, for: indexPath) as? RoleCollectionViewCell {
return cell
}
case .barber:
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: RoleCollectionViewCell.name, for: indexPath) as? RoleCollectionViewCell {
let activeBarberImage = UIImage(named: "barber_a")
let deactiveBarberImage = UIImage(named: "barber_b")
cell.setActive(image: activeBarberImage!, borderColor: burbColor.cgColor)
cell.setTitle(text: "Barber")
cell.setDescription(text: "I can make you look real cool")
return cell
}
}
return UICollectionViewCell.init()
}