我正在研究Core Plot项目并遇到问题。我的X轴标签都不止一行。我希望它们完全居中,我迄今能够做到的唯一方法是手动向NSString(即标签)添加空格。请参阅下面的代码...在Core Plot中定位多行标签,iOS
NSDictionary *dataTemp=[NSDictionary dictionaryWithObjectsAndKeys:white,@"
White\rBuilding\r(220 max)",rec,@"Rec. Hall\r(240 max)",im,@" IM\rBuilding\r(60
max)",fit,@"Fitness\r Loft\r(40 max)",nil];
我认为有一种方法来对齐标签编程,但我还没有找到它。我会很感激任何帮助。这里有一个图表标签的样子
这里就是我定义x轴标签的代码截图...
//Array containing all the names that will be displayed on the X axis
dates = [NSArray arrayWithObjects:@"Rec. Hall\r(240 max)", @" White\rBuilding\r(220
max)", @" IM\rBuilding\r(60 max)",
@"Fitness\r Loft\r(40 max)", nil];
这里就是我在做的标签代码图表
//X labels
int labelLocations = 0;
NSMutableArray *customXLabels = [NSMutableArray array];
for (NSString *day in dates) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:day
textStyle:x.labelTextStyle];
newLabel.tickLocation = [[NSNumber numberWithInt:labelLocations] decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
[customXLabels addObject:newLabel];
labelLocations++;
[newLabel release];
}
x.axisLabels = [NSSet setWithArray:customXLabels];
并添加NSLinebreakByWordWrapping使换行符与整个单词 – 2013-03-09 01:42:40
对不起,没有工作发生...我已经编辑我的帖子,虽然包括更多的代码。我认为创作标签的方式有些不妥。当我尝试newLabel.textAlignment时,它不起作用。 – pj409 2013-03-09 01:53:28
@ pj409尝试使用labelAlignment = CPAlignmentCenter;并检查此链接 - https://code.google.com/p/core-plot/source/detail?r=cd1f17fc48# - 确保您点击“展开全部” – lifetimes 2013-03-09 01:57:25