首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CorePlot - multiLine属性标签

CorePlot - multiLine属性标签
EN

Stack Overflow用户
提问于 2016-03-10 11:06:55
回答 1查看 120关注 0票数 0

我正在尝试使用coreplotNSAttributedString创建一个自定义标签。当我的字符串有1行时,一切都很好。

当我希望使用代码拥有2行字符串时,就会出现此问题:

代码语言:javascript
复制
NSMutableAttributedString* remFinalLabel = [remAttrStr mutableCopy];
NSMutableAttributedString *newLineAttrStr = [[NSMutableAttributedString alloc]initWithString:@"\n"];
[remFinalLabel appendAttributedString:newLineAttrStr];
[remFinalLabel appendAttributedString:rem2AttrStr];

结果如下所示:即使是第一个字符串也没有正确显示。如何设置自定义标签中的行数?

我创建标签的代码:

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-10 11:24:48

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

试试这个:-

代码语言:javascript
复制
    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

快乐编码!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35914689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档