Я пытаюсь создать специальную метку для coreplot
, используя NSAttributedString
. Все работает нормально, когда у строк есть 1 строка.CorePlot - multiLine присваиваемая метка
Проблема возникает, когда я хочу иметь 2 строк строки с помощью кода:
NSMutableAttributedString* remFinalLabel = [remAttrStr mutableCopy];
NSMutableAttributedString *newLineAttrStr = [[NSMutableAttributedString alloc]initWithString:@"\n"];
[remFinalLabel appendAttributedString:newLineAttrStr];
[remFinalLabel appendAttributedString:rem2AttrStr];
Результат выглядит следующим образом: правильно отображается даже не первая строка. Как установить количество строк в пользовательской метке?
Мой код для создания этикеток:
NSMutableArray* labelsStrings = [NSMutableArray arrayWithObjects:strAttr1, strAttr2, strAttr3, nil];
NSMutableArray *ticksLocations = [NSMutableArray arrayWithObjects:@0.5, @1.5, @2.5, nil];
NSMutableArray* customLabels = [[NSMutableArray alloc] init];
NSUInteger labelLocation = 0;
@try {
for (NSNumber *tickLocation in ticksLocations) {
NSAttributedString* currentLabel = [labelsStrings objectAtIndex:labelLocation];
CPTTextLayer *txtLayer = [[CPTTextLayer alloc] initWithAttributedText:currentLabel];
CPTAxisLabel* newLabel = [[CPTAxisLabel alloc] initWithContentLayer:txtLayer];
newLabel.tickLocation = tickLocation;
newLabel.offset = 0.0f;
newLabel.alignment = CPTAlignmentLeft;
[customLabels addObject:newLabel];
labelLocation++;
}
}
@catch (NSException * e) {
DLog(@"An exception occurred while creating date labels for x-axis");
}
@finally {
y.axisLabels = [NSSet setWithArray:customLabels];
}
y.majorTickLocations = [NSSet setWithArray:ticksLocations];
Размер текстового слоя, который автоматически соответствует тексту. Этот шаг не должен быть лишним. –
Работал для меня. Благодаря! – izik461