我正在使用axisLabels,并且需要使标签并排且两者之间没有空格。但是,似乎标签会自动调整为文本大小。有没有办法设置标签的宽度?
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.weightHistoryChart.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:@1.0, @3.0, @5.0, nil];
NSMutableSet *customLabels = [NSMutableSet setWithCapacity:3];
for ( NSNumber *tickLocation in customTickLocations ) {
CPTTextLayer *layer = [[CPTTextLayer alloc] initWithText:@"label"];
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithContentLayer:layer];
newLabel.tickLocation = tickLocation;
newLabel.offset = 0;
[newLabel.contentLayer setBackgroundColor:[UIColor lightGrayColor].CGColor];
[customLabels addObject:newLabel];
}
x.axisLabels = customLabels;
有空间:
删除空间:
您可以在上设置左右填充,CPTTextLayer
以在文本两侧留出多余的空间。但是,如果您想要的只是标签后面的实心矩形,则在标签后面添加图层注释可能会更好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句