Ios7 更新到iOS 7后,标签未显示
我用了核心情节。在更新(从Xcode4.6升级到Xcode5,即ios 7)之前,一切都正常运行和显示。但更新后,AxisLabel不会显示。下面是我的代码Ios7 更新到iOS 7后,标签未显示,ios7,core-plot,Ios7,Core Plot,我用了核心情节。在更新(从Xcode4.6升级到Xcode5,即ios 7)之前,一切都正常运行和显示。但更新后,AxisLabel不会显示。下面是我的代码 barChartView.frame = CGRectMake(0,30, 320, 440); barChartView.backgroundColor = [UIColor clearColor]; CGRect barChartFrame=CGRectMake(0, 40, 250, 440); if ([U
barChartView.frame = CGRectMake(0,30, 320, 440);
barChartView.backgroundColor = [UIColor clearColor];
CGRect barChartFrame=CGRectMake(0, 40, 250, 440);
if ([UIScreen mainScreen].bounds.size.height > 500)
{
barChartView.frame=CGRectMake(0,50,320,460);
barChartFrame=CGRectMake(0, 60, 250, 460);
}
CPTXYGraph *localBarChart = [[CPTXYGraph alloc] initWithFrame:barChartFrame];
localBarChart.backgroundColor = [[UIColor clearColor] CGColor];
localBarChart.plotAreaFrame.masksToBorder = NO;
localBarChart.cornerRadius=5;
localBarChart.paddingLeft = 70.0;
localBarChart.paddingTop = 20.0;
localBarChart.paddingRight = 20.0;
localBarChart.paddingBottom = PADDING_BOTTOM;
self.barChart= localBarChart;
[localBarChart release];
barChartView.hostedGraph = barChart;
// Add plot space for horizontal bar charts
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)barChart.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat([self.topicArray count]+1)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0.0) length:CPTDecimalFromInteger(100)];
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineColor = [[CPTColor blackColor]colorWithAlphaComponent:0.5];
axisLineStyle.lineWidth = 1.0f;
// 2 - Get the graph's axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.barChartView.hostedGraph.axisSet;
static CPTTextStyle *titleStyle = nil;
static CPTTextStyle *axisLabelTextStyle = nil;
//CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barChart.axisSet;
CPTXYAxis *x = axisSet.xAxis;
CPTMutableTextStyle *newStyle = [x.labelTextStyle mutableCopy];
newStyle.color = [CPTColor redColor];
newStyle.fontName = FONT_FAMILY_NAME;
newStyle.fontSize = 14.0f;
titleStyle = newStyle;
CPTMutableTextStyle *labelStyle = [x.labelTextStyle mutableCopy];
labelStyle.color = [CPTColor redColor];
newStyle.fontName = FONT_FAMILY_NAME;
labelStyle.fontSize = 14.0f;
axisLabelTextStyle = labelStyle;
x.axisLineStyle = axisLineStyle;
x.majorTickLineStyle = nil;
x.minorTickLineStyle = nil;
x.majorIntervalLength = CPTDecimalFromString(@"4");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.titleTextStyle = titleStyle;
x.title = @"Topics";
// x.titleLocation = CPTDecimalFromInteger(([arrBackData count]+1)/2);
x.titleOffset = TITLE_OFFSET;
x.labelTextStyle = axisLabelTextStyle;
// Define some custom labels for the data elements
x.labelRotation = M_PI/4;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
NSMutableArray *customTickLocations=[[NSMutableArray alloc]init];
for (int tickLocationIndex=1; tickLocationIndex<[self.topicArray count]+1;tickLocationIndex++ )
{
NSString *axisLabels=[NSString stringWithFormat:@"%d",tickLocationIndex];
[customTickLocations addObject:axisLabels];
}
NSMutableArray *xAxisLabels=[[NSMutableArray alloc] init];
for(int i=1;i<[self.topicArray count]+1;i++)
{
NSString *axisLabels;
axisLabels=[self.topicArray objectAtIndex:i-1];
[xAxisLabels addObject:axisLabels];
}
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
newLabel.offset = 1.00;
newLabel.rotation = M_PI/2;
[customLabels addObject:newLabel];
[newLabel release];
}
[customTickLocations release];
[xAxisLabels release];
x.axisLabels = [NSSet setWithArray:customLabels];
CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle = axisLineStyle;
y.majorTickLineStyle = nil;
y.minorTickLineStyle = nil;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.majorGridLineStyle=nil;
y.labelTextStyle = axisLabelTextStyle;
y.majorIntervalLength = CPTDecimalFromString(@"10");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y.titleTextStyle = titleStyle;
y.title = @"No. of Question(Percentage)";
y.titleOffset = 30.0f;
y.titleLocation = CPTDecimalFromFloat(60.0f);
if ([UIScreen mainScreen].bounds.size.height > 500)
{
y.titleLocation = CPTDecimalFromFloat(70.0f);
}
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
[formatter setMaximumFractionDigits:0];
y.labelFormatter = formatter;
CPTBarPlot *barPlot = [[CPTBarPlot alloc] init];
CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor blackColor];
barLineStyle.lineWidth = 0.2;
NSString *pathToFillImage;
pathToFillImage = [[NSBundle mainBundle] pathForResource:@"SkipBar" ofType:@"png"];
CPTImage *fillImage = [CPTImage imageForPNGFile:pathToFillImage];
fillImage.tiled = NO;
CPTFill *areaGradientFill = [CPTFill fillWithImage:fillImage];
barPlot.fill = areaGradientFill;
barPlot.dataSource = self;
barPlot.baseValue = CPTDecimalFromString(@"0.0");
barPlot.barWidth= CPTDecimalFromDouble(0.3);
barPlot.borderColor = [[UIColor clearColor] CGColor];
barPlot.cornerRadius = 0.0f;
barPlot.shadowColor = nil;
barPlot.shadowRadius = 0.0;
barPlot.lineStyle = barLineStyle;
barPlot.identifier = @"Bar Plot ";
barPlot.barOffset = CPTDecimalFromDouble(0.0);
barPlot.opacity = 0.0f;
[barChart addPlot:barPlot toPlotSpace:plotSpace];
[barPlot release];//#new
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.duration = 5.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeBoth;
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[barPlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];
barPlot = [[CPTBarPlot alloc] init];
barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.709) green:(0.023) blue:(0.031) alpha:(1.0f)] ];
barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.756) green:(0.050) blue:(0.050) alpha:(1.0f)] ];
NSString *pathToFillImage1;
pathToFillImage1 = [[NSBundle mainBundle] pathForResource:@"WrongBar" ofType:@"png"];
CPTImage *fillImage1 = [CPTImage imageForPNGFile:pathToFillImage1];
fillImage.tiled = NO;
CPTFill *areaGradientFill1 = [CPTFill fillWithImage:fillImage1];
barPlot.fill = areaGradientFill1;
barPlot.baseValue = CPTDecimalFromString(@"0.0");
barPlot.barWidth= CPTDecimalFromDouble(0.3);
barPlot.dataSource = self;
barPlot.lineStyle = barLineStyle;
barPlot.borderColor = [[UIColor clearColor] CGColor];
barPlot.cornerRadius = 0.0f;
barPlot.identifier = @"Bar Plot 1";
barPlot.opacity = 0.0f;
barPlot.shadowRadius = 0.0;
barPlot.barOffset = CPTDecimalFromDouble(0.0);
barPlot.shadowColor = nil;
[barChart addPlot:barPlot toPlotSpace:plotSpace];
[barPlot release];//#new
fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.duration = 5.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeBoth;
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[barPlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];
// Second bar plot
barPlot = [[CPTBarPlot alloc] init];
barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.588) green:(0.717) blue:(0.035) alpha:(1.0f)] ];
barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.239) green:(0.588) blue:(0.031) alpha:(1.0f)] ];
NSString *pathToFillImage2;
pathToFillImage2 = [[NSBundle mainBundle] pathForResource:@"RightBar" ofType:@"png"];
CPTImage *fillImage2 = [CPTImage imageForPNGFile:pathToFillImage2];
fillImage2.tiled = NO;
CPTFill *areaGradientFill2 = [CPTFill fillWithImage:fillImage2];
barPlot.fill = areaGradientFill2;
barPlot.dataSource = self;
barPlot.baseValue = CPTDecimalFromString(@"0.0");
barPlot.barWidth=CPTDecimalFromDouble(0.3);
barPlot.cornerRadius = 0.0f;
barPlot.shadowRadius = 0.0;
barPlot.borderColor = [[UIColor clearColor] CGColor];
barPlot.shadowColor = nil;//[[UIColor clearColor] CGColor];
barPlot.barOffset = CPTDecimalFromDouble(0.0);
barPlot.lineStyle = barLineStyle;
barPlot.identifier = @"Bar Plot 2";
barPlot.opacity = 0.0f;
[barChart addPlot:barPlot toPlotSpace:plotSpace];
[barLineStyle release];
[barPlot release];//#new
barChartView.frame=CGRectMake(0,30,320,440);
barChartView.backgroundColor=[UIColor clearColor];
CGRect barChartFrame=CGRectMake(0,40,250,440);
如果([UIScreen mainScreen].bounds.size.height>500)
{
barChartView.frame=CGRectMake(0,50320460);
barChartFrame=CGRectMake(0,60,250,460);
}
CPTXYGraph*localBarChart=[[CPTXYGraph alloc]initWithFrame:barChartFrame];
localBarChart.backgroundColor=[[UIColor clearColor]CGColor];
localBarChart.plotAreaFrame.masksToBorder=否;
localBarChart.cornerRadius=5;
localBarChart.paddingLeft=70.0;
localBarChart.paddingTop=20.0;
localBarChart.paddingRight=20.0;
localBarChart.paddingBottom=填充底部;
self.barChart=localBarChart;
[本地条形图发布];
barChartView.hostedGraph=条形图;
//为水平条形图添加打印空间
CPTXYPlotSpace*plotSpace=(CPTXYPlotSpace*)条形图。默认plotSpace;
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)长度:CPTDecimalFromFloat([self.topicArray count]+1)];
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0.0)长度:CPTDecimalFromInteger(100)];
CPTMutableLineStyle*axisLineStyle=[CPTMutableLineStyle];
axisLineStyle.lineColor=[[CPTColor blackColor]colorWithAlphaComponent:0.5];
axisLineStyle.lineWidth=1.0f;
//2-设置图形的轴
CPTXAxisSet*axisSet=(CPTXAxisSet*)self.barChartView.hostedGraph.axisSet;
静态CPTTextStyle*标题样式=零;
静态CPTTextStyle*axisLabelTextStyle=nil;
//CPTXAxisSet*axisSet=(CPTXAxisSet*)条形图。axisSet;
CPTXYAxis*x=axisSet.xAxis;
CPTMutableTextStyle*newStyle=[x.labelTextStyle可变表复制];
newStyle.color=[CPTColor redColor];
newStyle.fontName=FONT\u FAMILY\u NAME;
newStyle.fontSize=14.0f;
标题风格=新闻风格;
CPTMutableTextStyle*labelStyle=[x.labelTextStyle可变表复制];
labelStyle.color=[CPTColor redColor];
newStyle.fontName=FONT\u FAMILY\u NAME;
labelStyle.fontSize=14.0f;
axisLabelTextStyle=labelStyle;
x、 axisLineStyle=axisLineStyle;
x、 majorTickLineStyle=nil;
x、 minorTickLineStyle=nil;
x、 majorIntervalLength=CPTDecimalFromString(@“4”);
x、 正交坐标CIMAL=CPTDecimalFromString(@“0”);
x、 titleTextStyle=标题样式;
x、 标题=@“主题”;
//x.titleLocation=CPTDecimalFromInteger([arrBackData count]+1)/2);
x、 titleOffset=标题偏移量;
x、 labelTextStyle=axisLabelTextStyle;
//为数据元素定义一些自定义标签
x、 labelRotation=M_PI/4;
x、 labelingPolicy=CPTAxisLabelingPolicyNone;
NSMutableArray*customTickLocations=[[NSMutableArray alloc]init];
对于(int tickLocationIndex=1;tickLocationIndex我解决了我的问题。这是因为文件CPTTextStylePlatformSpecific.m文件中的uilinebreakmodewrap
&uitextrallignment
1) 将uilinebreakmodewrapp
替换为nslinebreakbywrapping
2) 将UITextAlignment
替换为NSTextAlignment
就是
[self drawInRect:rect
withFont:theFont
lineBreakMode:UILineBreakModeWordWrap
alignment:(UITextAlignment)style.textAlignment];
将上述代码替换为
[self drawInRect:rect
withFont:theFont
lineBreakMode:NSLineBreakByWordWrapping
alignment:(NSTextAlignment)style.textAlignment];
这已在Core Plot 1.3版中修复。