Ios 设置单元格圆角和边框宽度会使tableview的滚动速度非常慢
我想绕过tableview单元格的一角,使它们之间的间隙更大 我在cellForRowAtIndexPath中这样做:Ios 设置单元格圆角和边框宽度会使tableview的滚动速度非常慢,ios,uitableview,quartz-graphics,Ios,Uitableview,Quartz Graphics,我想绕过tableview单元格的一角,使它们之间的间隙更大 我在cellForRowAtIndexPath中这样做: static NSString* CellIdentifier = @"normal"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; if(cell == nil) cell = [[UITableViewCell alloc]
static NSString* CellIdentifier = @"normal";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
CALayer* layer = cell.layer;
[layer setCornerRadius:8.0f];
[layer setMasksToBounds:YES];
[layer setBorderWidth:2.0f];
通过调用setBorderWidth,tableview的滚动速度变得非常慢。没有它,它就像一个魅力
那么,如何使单元格角圆化并更快地设置边框宽度呢?我尝试了很多次使其快速工作。但是,当它用于许多对象时,它的工作速度非常慢 我可以推荐什么: 使用背景图像,而不是使用图层特性。比如说 或者使用tableView样式-
UITableViewStyleGroup
在您的情况下,表视图中的对象可能不多,因此请在创建单元格时通过设置边框等方式对其进行优化:
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
CALayer* layer = cell.layer;
[layer setCornerRadius:8.0f];
[layer setMasksToBounds:YES];
[layer setBorderWidth:2.0f];
}
不要每次都设置图层属性,只需在创建单元时这样做一次即可
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
CALayer* layer = cell.layer;
[layer setCornerRadius:8.0f];
[layer setMasksToBounds:YES];
[layer setBorderWidth:2.0f];
}
我只有几个元素,大约30个,而我的iphone5正与之斗争很多,最好创建背景图像或使用分组表视图。我是说列表中的30个元素,我认为10个元素通常会使设备上的ui速度变慢,这是非常少的,有了模拟器,一切都应该正常。这是因为它总是需要重新绘制单元格的图层。单元格是在情节提要上定义的,所以这并不重要。这非常有效。你知道如何使细胞的imageView.layer工作吗?