My requirement is parts of text should be displayed as bold and colored within each cell of a UITableview. I have managed it using the NSMutableAttributedString, CATextLayer and cell's contenview's layer. Below is the code that i have used to display.
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;
}
The Problem is when I scroll the table fast the text is displaying as animated(Overlapping), and after stopped scrolling it is displaying properly. Please find the below reference image
Could any one please help me why this overlapping is happening only when i scroll the table?