UITableView(iOS7)中的圆角

joa*_*oan 28 objective-c rounded-corners uitableview ios7

在iOS7中,如何在UITableView中绘制单元格的圆角?看一个例子:

在此输入图像描述

Hus*_*bir 29

你的UITableview包含UIView,所以只需使用下面的代码行使其成为圆角.在tableview方法中写下这行代码

//如果iOS版本<10

对于Objective-C:

cell.contentView.layer.cornerRadius = 5;
cell.contentView.layer.masksToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

对于Swift:

cell.contentView.layer.cornerRadius = 5
cell.contentView.layer.masksToBounds = true
Run Code Online (Sandbox Code Playgroud)

//如果iOS版本> = 10

对于Objective-C:

cell.layer.cornerRadius = 5;
cell.layer.masksToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

对于Swift:

cell.layer.cornerRadius = 5
cell.layer.masksToBounds = true
Run Code Online (Sandbox Code Playgroud)

注意:无需QuartzCore framework显式导入.

  • 你的意思是cell.contentView而不是视图? (2认同)

hid*_*ame 13

我将UITableViewCell子类化,并且不得不省略contentView以使其工作.

cell.layer.cornerRadius = 10 cell.layer.maskToBounds = true