Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my UIButton not showing up?

This is the code I'm using:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 50, 70)];
    [self.view addSubview:button];
    if (buttonArray == nil) {
        buttonArray = [[NSMutableArray alloc] init];
    }
    [buttonArray addObject:button];
    [button release];

The butting isn't displaying, however. Any ideas why?

like image 423
Andrew Avatar asked Feb 24 '23 20:02

Andrew


1 Answers

You're initializing it wrong. Try the following:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 200, 50, 70);
[self.view addSubview:button];
if (buttonArray == nil) {
    buttonArray = [[NSMutableArray alloc] init];
}
[buttonArray addObject:button];
like image 76
Erik B Avatar answered Mar 07 '23 13:03

Erik B