I have 3 different buttons, and I am using for loop to display it in my UIView. The problem is, there is only one button shown.
float yButton = 50.0;
for (int i = 0; i < 2; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(80.0, yButton + 70.0, 160.0, 40.0);
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button];
[button setTag:i];
}
Also, how do I set the button titles to A, B, and C (since there are only 3 buttons).
You give all of the buttons the same frame. You need to increment the
yorigin.At the end of the loop, do this:
To set the titles, create an array with the three titles:
then in the loop: