1.第一次添加框架-> QuartzCore.framework 向您的项目
然后导入头文件在你 ViewController.m 文件
#import <QuartzCore/CALayer.h>
2.添加下列代码,在你 cellForRowAtIndexPath 方法:
- (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;
}