John John - 8 months ago 50
Swift Question

Get Indexpath Value in UiCollectionViewCell Class

I have a UiCollectionViewCell Class as follow:

class DateCollectionViewCell: UICollectionViewCell {

let dateLabel = UILabel()
override func 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


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.

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