我正在做一个 Core Plot 项目并且遇到了问题。我的 X 轴标签都不止一行。我希望它们完全居中,到目前为止我能够做到这一点的唯一方法是手动将空格添加到作为标签的 NSString 中。请看下面的代码...
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];