senty senty - 6 months ago 29x
Swift Question

Setting Activity Indicator to CollectionViewCell

I am trying to display activity indicator for the initial load time for each collection view cell. I tried placing it in

however, it's getting created 20 pixels above the cell for some reason.

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("AACollectionViewCell", forIndexPath: indexPath) as! AACollectionViewCell

let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray) =
// Also tried =


return cell

What is the proper way of handling it?

Edit: I also tried this but it's not creating activityIndicator anywhere

let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray) =

Answer gives you the frame of contentView from its superview's coordinate system. What you should do: = CGPointMake(cell.contentView.frame.size.width / 2, cell.contentView.frame.size.height / 2)