我的要求是部分文本应该在 UITableview 的每个单元格中显示为粗体和彩色。我使用 NSMutableAttributedString、CATextLayer 和单元格的 contenview 层对其进行了管理。下面是我用来显示的代码。
CATextLayer *textLayer = nil; //used to draw the attributed string
CALayer *layer = nil;
if(cell == nil) {
textLayer = [[CATextLayer alloc] init];
textLayer.backgroundColor = [UIColor clearColor].CGColor;
[textLayer setForegroundColor:[[UIColor clearColor] CGColor]];
[textLayer setContentsScale:[[UIScreen mainScreen] scale]];
textLayer.wrapped = YES;
layer = cell.contentView.layer;
[layer addSublayer:textLayer];
textLayer = nil;
}
//get the layer by nesting sublayer of cell layer because we don't have tag property for the layer and textlayer.
if (!layer) {
layer = cell.contentView.layer;
}
for (id subLayer in layer.sublayers) {
if ([subLayer isKindOfClass:[CATextLayer class]]) {
// NSLog(@"found textlayer");
textLayer = subLayer;
textLayer.string = nil;
}
}
textLayer.frame = CGRectMake(53.0f, 23.0f, 240.0f, attributedStrHeight);
if([self isNotNull:mAttrbtdStr]) {
textLayer.string = mAttrbtdStr;
}
问题是当我快速滚动表格时,文本显示为动画(重叠),并且在停止滚动后显示正确。请找到下面的参考图片
任何人都可以帮助我为什么只有当我滚动表格时才会发生这种重叠?