0
cellForItemAtIndexPathを使用してUICollectionViewにセルを追加すると、最初のセルをターゲットにして、セル内の画像に色付きのオーバーレイを追加しようとしています。しかし、対応する回数呼び出されていないように見えても、コードは複数のセルをターゲットにしているように見えます(3つまたは4つのセルにオーバーレイを適用することがありますが、 2回目はreloadData()が呼び出されたときです)。最初のセルにカラーオーバーレイを適用するにはどうすればよいですか?uicollectionview内の特定のセルを変更する
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProfileCollectionViewCell
if(self.userList.count > 0) {
cell.frame.size = CGSize(width: 202, height: 207)
if(indexPath.item < self.userList.count) {
cell.myImage.image = self.userList[indexPath.item].image
cell.myImage.layer.cornerRadius = cell.myImage.frame.size.width/2
cell.myImage.layer.masksToBounds = true
if(indexPath.item == 0) {
print("Overlay")
let circlePath = UIBezierPath(arcCenter: CGPoint(x: cell.frame.width/2, y: cell.frame.height/2), radius: CGFloat((cell.myImage?.frame.size.width)!/2), startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
shapeLayer.fillColor = self.overlayColor.CGColor
cell.layer.addSublayer(shapeLayer)
}
}
}
return cell
}
ありがとうございました。それはそれを行い、私がリンクされていると思ったいくつかの他の問題を整理するのを助けました。 – Maniacbob