ladookie
ladookie

Reputation: 1371

How to round the courners of a UIImageView in a tableViewCell

I'm trying to have the uiimagview have rounded corners in a tableviewcell with this code:

#import <QuartzCore/QuartzCore.h>    
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomepwnerItemCell *cell = (HomepwnerItemCell *)[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];    

    Possession *possession = [self.possessions objectAtIndex:indexPath.row];
    cell.valueLabel.text = [@"$" stringByAppendingString:[[NSNumber numberWithInt:possession.valueInDollars] stringValue]];
    cell.nameLabel.text = possession.possessionName;

    UIImage *image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];      
    UIImageView *roundedImage = [[UIImageView alloc] initWithImage:image];
    roundedImage.layer.masksToBounds = YES;
    roundedImage.layer.cornerRadius = 10.0;
    cell.imageView = roundedImage;
    // cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];
    return cell;
}

but the images show up blank in the tableViewCells when I run it.

it works fine if I just do cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey]; (but without the rounded corners)

What am I doing wrong?

Upvotes: 2

Views: 2624

Answers (2)

Ravi Kumar Karunanithi
Ravi Kumar Karunanithi

Reputation: 2218

use

cell.imageView.layer.cornerRadius=20;  //Use as ur specified corner length

also implement

  <QuartzCore/QuartzCore.h>

Upvotes: 1

Vishal Kardode
Vishal Kardode

Reputation: 971

YOu need to use the quartz framework. Here is the code for cornering and adding border to image

cell.imageView.layer.cornerRadius = 10.0;
cell.imageView.layer.borderColor = [UIColor blackColor].CGColor;

cell.imageView.layer.borderWidth = 1.2;
cell.imageView.clipsToBounds = YES;

First Set Image to imageview, then change the imageview layer

Upvotes: 10

Related Questions