UI button not showing - please help
I have an interesting problem. When I add a UIImageView it works fine
This code works:
- (void) showAd {
CGRect myAdRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
UIImageView *myAd = [[UIImageView alloc] initWithFrame:myAdRect];
[myAd setImage:[UIImage imageNamed:@"Empty Red Box.png"]];
myAd.alpha = 0.0f;
[self.view addSubview:myAd];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];
myAd.alpha = 1.0f;
myAdButton.alpha = 1.0f;
[UIView commitAnimations];
[myAd release];
}
BUT, when I try to do something very similar adding a UIButton like this:
- (void) showAd {
//create button
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(100,200, 100, 50); // position in the parent view and set the size of the button
[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
//add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[self.view addSubview:myButton];
[myButton release];
}
It doesn't work. By doesn't work, I mean no button appears on the screen. I have no idea what I could be doing wrong.
Ideas?
|