简体   繁体   English

在UICollectionViewCell类中获取IndexPath值

[英]Get IndexPath Value in UICollectionViewCell Class

I have a UiCollectionViewCell Class as follow: 我有一个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)

    }
}

I want to change the Y-positon of my first row first column cell label only, rest of the cells label remain unchanged.So for this I need IndexPath value so I can check for section and row of current cell. 我只想更改第一行第一列单元格标签的Y位,其余单元格标签保持不变,因此为此我需要IndexPath值,以便可以检查当前单元格的部分和行。

How can I get this ?? 我怎么能得到这个? Is there any other way to do what I want to get ??? 还有其他方法可以做我想得到的吗?

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM