如何设置 Coreplot axisLabels 宽度?
How to set Coreplot axisLabels width?
我正在处理 axisLabels,需要并排制作标签,中间没有 space。但是,标签似乎已根据文本自动调整大小。有没有办法设置标签的宽度?
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;
与space:
删除space:
您可以在 CPTTextLayer
上设置左右填充,以便在文本周围留下额外的 space。但是,如果您只想要标签后面的实心矩形,那么在标签后面添加图层注释可能会更好看。
我正在处理 axisLabels,需要并排制作标签,中间没有 space。但是,标签似乎已根据文本自动调整大小。有没有办法设置标签的宽度?
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;
与space:
删除space:
您可以在 CPTTextLayer
上设置左右填充,以便在文本周围留下额外的 space。但是,如果您只想要标签后面的实心矩形,那么在标签后面添加图层注释可能会更好看。