Мое требование - части текста, которые должны быть выделены жирным шрифтом и окрашены в каждую ячейку UITableview. Я справился с ней, используя слой NSMutableAttributedString, CATextLayer и слой Containview. Ниже приведен код, который я использовал для отображения.Строка NSAttributed с CATextLayer внутри UITableView
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;
}
Проблема, когда я прокручиваю таблицу поститься текст отображения в виде анимированных (Перекрытие), и после того, как перестал прокрутке он отображается неправильно. Вы можете найти ниже эталонного изображения
Может ли один помочь мне, почему это перекрытие происходит только тогда, когда я прокручивать таблицу?
Спасибо Андреа, второе решение для меня работало. Ниже приведен код, который я использовал для его исправления. NSMutableDictionary * newActions = NSMutableDictionary * newActions = [[NSMutableDictionary Alloc] initWithObjectsAndKeys: [NSNull нуль], @ "onOrderIn", [NSNull нуль], @ "onOrderOut", [NSNull нуль], @ "подслоя", [NSNull null], @ "contents", [NSNull null], @ "bounds", nil]; layer.actions = newActions; [newActions release]; –
NSMutableDictionary * newActions = NSMutableDictionary * newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSNull null], @ "onOrderIn", [NSNull null], @ "onOrderOut", [NSNull null], @ "подслои", [NSNull null] , @ "contents", [NSNull null], @ "bounds", [NSNUll null], @ "position", [NSNUll null], @ "hidden", nil]; layer.actions = newActions; –
Рад, что вы это сделали :-) – Andrea