0

I'm messing around with AVFoundation and I'm trying to take thumbnails of videos that exist on my phone and display them in a collectionView. My cells are rounded (using quartzcore and changing the corner radius); I have two issues here. 1) I can't seem to properly round my asset thumbnails and 2) Since some of my videos were shot in portrait mode and some in landscape mode, I can't get them to all fill the cell uniformly.

I tried drawing the images in a circular frame using a bezier path, but that didn't work.

Code below, any and all help would be appreciated.

enter image description here

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    videoCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"videoCell" forIndexPath:indexPath];

    ALAsset *asset = [self.videoArray objectAtIndex:indexPath.row];
    UIImage *thumbnail = [UIImage imageWithCGImage:asset.thumbnail];


    cell.layer.cornerRadius = thumbnail.size.width/2;
    cell.highlighted = YES;

    cell.image.image = thumbnail;
    cell.image.contentMode = UIViewContentModeScaleAspectFill;
    cell.layer.borderWidth = 1.0f;
    cell.layer.borderColor = (__bridge CGColorRef)([UIColor clearColor]);

    return cell;

}

Hardcoding the cornerradius of my cell to be half of the width makes it a perfect circle; hopefully I can fix the size of the thumbnail so that I can keep that code for the cell cornerradius the same.

3
  • You want to set the corner radius to be based on the size of the image view, not the size of the thumbnail.
    – rmaddy
    Aug 21, 2015 at 18:21
  • 1
    Do not use this lazy way of making a circular view. If you want a circular mask, mask to a circle. This business with misusing the corner radius of the layer, though widespread, is just wrong.
    – matt
    Aug 21, 2015 at 18:23
  • @matt What exactly is wrong about using the corner radius to make a circular view? I heard this before, but never actually got the reasoning behind it. Dec 11, 2017 at 12:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.