自定义标签设置 - 字体,颜色,尺寸未使用?

时间:2016-08-19 01:57:52

标签: core-plot

从Plot Gallery示例--LabelingPolicyDemo.m,它使用无标签策略,并使用与轴标题相同的样式设置每个标签:

CPTMutableLineStyle *majorTickLineStyle = [axisLineStyle mutableCopy];
majorTickLineStyle.lineWidth = 3.0;
majorTickLineStyle.lineCap   = kCGLineCapRound;

CPTMutableLineStyle *minorTickLineStyle = [axisLineStyle mutableCopy];
minorTickLineStyle.lineWidth = 2.0;
minorTickLineStyle.lineCap   = kCGLineCapRound;

// Text styles
CPTMutableTextStyle *axisTitleTextStyle = [CPTMutableTextStyle textStyle];
axisTitleTextStyle.fontName = @"Helvetica-Bold";
axisTitleTextStyle.color = [CPTColor redColor]; // differs from sample

// Tick locations
CPTNumberSet *majorTickLocations = [NSSet setWithObjects:@0, @30, @50, @85, @100, nil];

CPTMutableNumberSet *minorTickLocations = [NSMutableSet set];
for ( NSUInteger loc = 0; loc <= 100; loc += 10 ) {
    [minorTickLocations addObject:@(loc)];
}

// Axes
// CPTAxisLabelingPolicyNone
CPTXYAxis *axisNone = [[CPTXYAxis alloc] init];
axisNone.plotSpace          = graph.defaultPlotSpace;
axisNone.labelingPolicy     = CPTAxisLabelingPolicyNone;
axisNone.orthogonalPosition = @1.0;
axisNone.tickDirection      = CPTSignNone;
axisNone.axisLineStyle      = axisLineStyle;
axisNone.majorTickLength    = majorTickLength;
axisNone.majorTickLineStyle = majorTickLineStyle;
axisNone.minorTickLength    = minorTickLength;
axisNone.minorTickLineStyle = minorTickLineStyle;
axisNone.title              = @"CPTAxisLabelingPolicyNone";
axisNone.titleTextStyle     = axisTitleTextStyle;
axisNone.titleOffset        = titleOffset;
axisNone.majorTickLocations = majorTickLocations;
axisNone.minorTickLocations = minorTickLocations;

CPTMutableAxisLabelSet *newAxisLabels = [NSMutableSet set];
for ( NSUInteger i = 0; i <= 5; i++ ) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"Label %lu", (unsigned long)i]
                                                      textStyle:axisNone.labelTextStyle];
    newLabel.tickLocation = @(i * 20);
    newLabel.offset       = axisNone.labelOffset + axisNone.majorTickLength / CPTFloat(2.0);

    [newAxisLabels addObject:newLabel];
}
axisNone.axisLabels = newAxisLabels;

但是生成的轴标签和标题应该与它们不匹配 - 大小,颜色或字体?标签文本样式显示为常量。

请参阅Axis Labeling Policies示例。

1 个答案:

答案 0 :(得分:0)

问题中的代码将红色文本样式设置为titleTextStyle,并在创建轴标签时使用labelTextStyle。这些文本样式是独立的,但如果您愿意,可以对两者使用相同的样式。