Search code examples
iosobjective-cuitableviewuiimageviewcalayer

Why am I unable to round the edges of my UIImageView?


On my Storyboard I have a UIImageView in a UITableViewCell, and I have an outlet to it in code. In initWithCoder (after I imported Quartz) I ask it to round the edges of the image, but it's never done, they're always square.

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.postThumbnail.layer.masksToBounds = YES;
        self.postThumbnail.layer.cornerRadius = 20.0;
        self.postThumbnail.opaque = NO;
    }
    return self;
}

They're for cells, so later on in my table view delegate I set the image. Do I have to round it there as well? Is there no way to universally say "keep it rounded"?


Solution

  • You can not have an outlet to UIImageView which placed on a cell. Change cornerRadius in cellForRowAtIndexPath method.