IOS UITableViewCell cell.imageView with rounded corner

Hi everyone, I'm trying to set cell.imageView cornerRadius , but it does not work.

 cell.imageView.layer.cornerRadius=9; 

Will it work or should I add a custom UIImageView in my cell to have rounded corners?

I also tried this

 cell.imageView.layer.borderWidth=2; cell.imageView.layer.borderColor=[[UIColor blackColor]CGColor]; 

But it also does not work. Has anyone encountered a similar problem?

+8
ios uitableview uiimageview
source share
1 answer

First add Framework - > QuartzCore.framework to your project
then import the header file ViewController.m file

 #import <QuartzCore/CALayer.h> 

Add the following code to your cellForRowAtIndexPath method:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"TableViewCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; // Rounded Rect for cell image CALayer *cellImageLayer = cell.imageView.layer; [cellImageLayer setCornerRadius:9]; [cellImageLayer setMasksToBounds:YES]; } cell.imageView.image = [UIImage imageNamed:@"image_name.png"]; return cell; } 
+27
source share

All Articles