I am fighting with the same problem - I want to add a button in my chart.
On Fri, Sep 4, 2009 at 10:23 AM, Chris Topher<pusill...@gmail.com> wrote:
> Thanks, Drew.
> I'll give that a go...
>
> Chris.
> Clumsily thumbed out on my iPhone.
> On Sep 4, 2009, at 12:12 AM, Drew McCormack <drewmc...@mac.com> wrote:
>
> Hi Chris,
> Probably the best approach is to add a new UIView in IB, and drop your
> hosting view into it as a subview. Then add your label to that new UIView.
> Make sense.
> Drew
Drew, I followed your advice. In Interface Builder I added I have a
regular UIView and I added a new CPHostingLayerView to it. I then
retrieve the hosting view and add programmatically a button:
CPTheme *theme = [CPTheme themeNamed:themeName];
barChart = (CPXYGraph *)[theme newGraph];
UIView *view = self.view;
CPLayerHostingView *hostingView;
for (UIView *v in view.subviews) {
if ([v class] == [CPLayerHostingView class]) {
hostingView = (CPLayerHostingView *)v;
NSLog(@"Found hosting view %@", hostingView);
}
}
hostingView.hostedLayer = barChart;
NSLog prints the the found object so I am sure it is not nil. Now I
create the button:
CGFloat labelDisplayWidth = 50.0;
CGFloat labelDisplayX = 25;
CGFloat labelDisplayY = 30;
CGFloat labelDisplayHeight = 47.0;
CGRect labelRect = CGRectMake(labelDisplayX, labelDisplayY,
labelDisplayWidth, labelDisplayHeight);
UIButton *buttonDisplay = [[UIButton alloc] initWithFrame:labelRect];
buttonDisplay.font = [UIFont boldSystemFontOfSize:60.0];
buttonDisplay.backgroundColor = [UIColor clearColor];
[buttonDisplay setTitle:[NSString stringWithFormat:@"Time vs. Whatever"]
forState:UIControlStateNormal];
[buttonDisplay setTitleColor:[UIColor blueColor]
forState:UIControlStateNormal];
Then I add the button and I try to bring it to front
[self.view addSubview:buttonDisplay];
[self.view bringSubviewToFront:buttonDisplay];
[buttonDisplay release];
It does not show up with this piece code. I tried also with
[self.view addSubview:buttonDisplay];
[hostingView bringSubviewToFront:buttonDisplay];
and the button does not show as well. Of course it works with
[hostingView addSubview:buttonDisplay];
[hostingView bringSubviewToFront:buttonDisplay];
but the button is inverted. Any ideas how to show my button?
Regards
Rambius
--
Tangra Mega Rock: http://www.radiotangra.com
On Sun, Sep 6, 2009 at 10:49 AM, Drew McCormack<drewmc...@mac.com> wrote:
>
> Did you actually connect the 'view' outlet in IB? Is self.view perhaps
> nil?
>
> Question 2: Why not just drop the button in the view in IB?
I found the issue - the background of the button was wrong so it
actually appeared but can not be seen.
Thank you.