Reputation: 667
I have set up my button as so:
CGRect button1Frame = CGRectMake(200, 200, 100, 100);
self.button1 = [[UIButton alloc] initWithFrame:button1Frame];
[self.button1 addTarget:self action:@selector(goToController1:)
forControlEvents:UIControlEventTouchDown];
self.button1.userInteractionEnabled = YES;
self.button1.opaque = YES;
self.button1.backgroundColor = [UIColor redColor];
[self.button1 setTitle:@"B1" forState:UIControlStateNormal];
[self.view addSubview:self.button1];
with my sender:
- (void) goToController1:(id)sender {
NSLog(@"Pressed");
}
and my view controller has been initialized properly. What would cause my button not to show up? I have checked to make sure everything is being called properly.
Upvotes: 3
Views: 2114
Reputation: 2632
You could try this:
button = [UIButton buttonWithType: UIButtonTypeSystem];
And then set the frame like this:
button.frame = CGRectMake(0,0,20,20);
The UIButton buttonWithType: method fixed my problem at one point. Not sure if it will make a difference in this case though. Just something to try.
Upvotes: 6