Change the code as shown below to set the first image to the / button you can use for a loop to create and set images in uibuttons
NSArray *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"], [UIImage imageNamed:@"Cover_1.png"], [UIImage imageNamed:@"Cover_2.png"], [UIImage imageNamed:@"Cover_3.png"], [UIImage imageNamed:@"Cover_4.png"], [UIImage imageNamed:@"Cover_5.png"], [UIImage imageNamed:@"Cover_6.png"], [UIImage imageNamed:@"Cover_7.png"],nil]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, 0, 200.0f, 200.0f); [button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; [button setImage:(UIImage*)[buttonImage objectAtIndex:1] forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; return button;
change line
[button setImage:(UIImage*)[buttonImage objectAtIndex:1] forState:UIControlStateNormal];
This will set the image to the button. You sent an array to set the image for the application to work
Sumanth
source share