Core-Plot: Annotation Position
I am working in a graph using the great framework core-plot (in desktop OSX). Up to know, i've managed to draw the table properly, but i am having a problem with an annotation.
I need to add an image annotation in the top-center position of the graph (not the plotting area). I've managed to position the annotation there at startup, but whenever i resize the window, the graph resizes, but the annotation keeps the initial position and don't move any more to the top-center position of the graph. I am doing something like this:
// This layer will be the annotation Content
CPBorderedLayer * logoLayer = [[(CPBorderedLayer *)[CPBorderedLayer alloc]
initWithFrame: CGRectMake(xMiddle, yTop, logoWidth,
logoHei开发者_运维百科ght) ] autorelease];
CPFill *fillImage = [CPFill fillWithImage:imgLogo];
logoLayer.fill = fillImage;
// Create a new annotation
CPAnnotation *annot = [[CPAnnotation alloc]init];
annot.contentLayer = logoLayer;
annot.displacement = CGPointMake(50,50);
// graph is my CPXYGraph instance
// Add annotation to the graph
[graph addAnnotation:annot];
Thanks for your help
Well, I would say that you need to change the location of the annotation every time the graph is resized. I don't think Core-Plot can do that for you. Retrieve the annotation, and modify its content layer's frame:
CPAnnotation *annot = [self.graph.annotations objectAtIndex:0];
annot.contentLayer.frame = CGRectMake(newXCoord, newYCoord, logoWidth, logoHeight);
精彩评论