ios - 设置单元格圆角和边框宽度使表格 View 滚动速度极慢

标签 ios uitableview quartz-graphics

我想将表格 View 单元格的角变圆,并使它们之间的间隙更大。

我在 cellForRowAtIndexPath 中这样做:

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的滚动变得非常慢。没有它,它就像一个魅力。

那么,如何更快地使单元格角变圆并设置边框宽度?

最佳答案

我尝试了很多次以使其快速运行。但当用于许多对象时,它的运行速度非常慢。

我可以推荐什么:

使用背景图像,而不是使用图层属性。看here例如

或者使用tableView样式 - UITableViewStyleGrouped

在您的情况下,表格 View 中的对象数量可能不是很多,因此请对其进行优化,例如在创建单元格时设置边框:

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];
}

关于ios - 设置单元格圆角和边框宽度使表格 View 滚动速度极慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604439/

相关文章:

ios - 将我的敌人类实现到游戏场景

iOS 系统权限警报 View 未显示在对象浏览器中

objective-c - NSImage + NSColor + 图案

ios - AWS Mobile hub with Cocoa pods Apple Mach-O 链接器错误

ios - 转到 NavigationViewController 中的第二个 View Controller

ios - Objective-C - iOS UITableView 底行删除时崩溃

ios - 重新加载 UITableView 数据并向下滚动到最后选择的单元格

uitableview - 在 UIAutomation 的自定义表部分标题 View 上设置accessibilityIdentifier

macos - 有没有办法将 ImageKit 的 IKSaveOptions 初始化为默认为 LZW 压缩的 TIFF?

cocoa - 转换为 JPEG 时我应该如何考虑 CGImageAlphaInfo?