John John - 1 year ago 127
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 ???

Answer Source
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download