UICollectionview cell selection

前端 未结 2 902
遇见更好的自我
遇见更好的自我 2021-01-31 11:12

i have made a grid of images and in order to show its selection i drew border for the image when selected. but the problem is when i select some image at the top and scroll down

2条回答
  •  面向向阳花
    2021-01-31 11:20

    This code is in Swift 3:

    if self.selectedItemIndexPath != nil && indexPath.compare(self.selectedItemIndexPath) == .orderedSame {
        cell.imageView!.layer.borderColor = UIColor.red.cgColor
        cell.imageView!.layer.borderWidth = 4.0
    } else {
        cell.imageView!.layer.borderColor = nil
        cell.imageView!.layer.borderWidth = 0.0
    }
    
    return cell
    

提交回复
热议问题