gpt4 book ai didi

ios - CorePlot - 多行属性标签

转载 作者:行者123 更新时间:2023-11-29 01:09:37 26 4
gpt4 key购买 nike

我正在尝试使用 NSAttributedStringcoreplot 创建自定义标签。当我的字符串只有 1 行时一切正常。

当我想使用代码有 2 行字符串时出现问题:

NSMutableAttributedString* remFinalLabel = [remAttrStr mutableCopy];
NSMutableAttributedString *newLineAttrStr = [[NSMutableAttributedString alloc]initWithString:@"\n"];
[remFinalLabel appendAttributedString:newLineAttrStr];
[remFinalLabel appendAttributedString:rem2AttrStr];

结果是这样的:甚至第一个字符串都没有正确显示。如何设置自定义标签的行数?

enter image description here

我创建标签的代码:

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

最佳答案

您可以通过设置 CPTAxisLabel 的内容层框架来实现这一点。

试试这个:-

    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:@"Your Text Here" textStyle:@"Text Style"];
[label.contentLayer setFrame:CGRectMake(0, 0, 40, 40)]; //change this frame according to your requirement

快乐编码..!!

关于ios - CorePlot - 多行属性标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com