在UICollectionViewCell类中获取IndexPath值



我有一个UiCollectionViewCell类如下:

class DateCollectionViewCell: UICollectionViewCell {
    let dateLabel = UILabel()
    override func awakeFromNib() {
        super.awakeFromNib()        
        dateLabel.frame = CGRectMake(0, 5, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))
        dateLabel.textAlignment = .Left
        dateLabel.font = UIFont(name: "HelveticaNeue", size: 13)
        dateLabel.adjustsFontSizeToFitWidth = false
        self.contentView.addSubview(dateLabel)
    }
}

我只想更改第一行第一列单元格标签的y位置,其余单元格标签保持不变。因此,对于这个,我需要IndexPath值,以便我可以检查当前单元格的section和row。

我怎么能得到这个??还有别的方法可以得到我想要的吗?

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
   let cell : DateCollectionViewCell = collectionView .dequeueReusableCellWithReuseIdentifier(CellIdentifier, forIndexPath: indexPath) as! DateCollectionViewCell 
   if indexPath.section == 0 && indexPath.row == 0  {
        // do your custom changes for the cell
    }
   return cell // your default cell
}

最新更新