我正在使用 core-plot 绘制条形图。我在 x 轴上显示了日期。我使用了以下代码:
NSDateFormatter * formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd MMM yy"];
double tickLocation=0.5;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[valuesArray count]];
for ( HistoryIndividualValueBean * value in valuesArray)
{
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[formatter stringFromDate:value.submittedTime] textStyle:x.labelTextStyle];
newLabel.tickLocation = [[NSNumber numberWithDouble:tickLocation++] decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI_2;
[customLabels addObject:newLabel];
[newLabel release];
}
[formatter release];
x.axisLabels = [NSSet setWithArray:customLabels];
这在 iPhone 上运行良好。但是在 ipad 上,它会在日期中显示奇怪的字符(我在上面已经格式化了)。请参考这张图片: