views:

352

answers:

2

Hi all,

I am using core-plot library to draw a bar-chart on my iPhone application and the problem arises when I try to add a label or some other views to the graph,

Actually the view I added is drawn vertically invert like this ........

The code is like

UILabel *lbl= [[UILabel alloc] initWithFrame:CGRectMake(250, 90, 70, 25)];
    [lbl setBackgroundColor:[UIColor redColor]];
    [lbl setText:@"HELLO"];
    [self.view addSubview:lbl];
    [lbl release];

I am not daring to play with core-plot library.

So is there any other way to do the things right? should I do a transform before adding the views?

If this is the solution then this will be costly because I have to add more than one subview.

Hoping my question is clear to everybody.

+1  A: 

Well, it looks like the core-plot view is inverted using a CGAffineTransform. Your view is probably inheriting the inversion from its superview. It's actually quite simple to do,

lbl.transform = CGAffineTransformMakeScale(1,-1);

Should do the trick. If you have to do it many times perhaps simplify it with something like,

CGAffineTransform verticalFlip = CGAffineTransformMakeScale(1,-1);
lbl.transform = verticalFlip;
otherLbl.transform = verticalFlip;

etc...

An x-axis flip would be CGAffineTransformMakeScale(-1,1);

Kenny Winker
Great I did it like.... lbl.transform = CGAffineTransformTranslate(verticalFlip,0,-300);
Madhup
Yes, we do this to match the coordinate systems for drawing between the Mac and iPhone. If you want this to be simpler, my recommendation would be to not add your UILabel to the graph's CPLayerHostingView, but to create a superview that encompasses the graph and add the UILabel to that.
Brad Larson
+1  A: 

To avoid guessing actual transform values you can try to use CGAffineTransformInvert function:

lbl.transform = CGAffineTransformInvert(self.view.transform);
Vladimir