[Solved] How to create 10 UIButtons in round shape in a for loop


You are seeing only “one” button that is elongated vertically, which makes you think you are only creating one button instead of 11?

The reason is the offset that you apply within your code:

 j = j + 10;

With the above, you are seeing 11 UIButtons overlapping each other, hence the illusion that there were only one button that is elongated vertically.

Try changing the amount of offset:

j = j + 50;

You would see, then, 11 UIButtons on the screen vertically.

As an aside, if you meant to only create 10 buttons instead of 11, the condition should be changed to:

for(int i = 0; i < 10; i++) //instead of using <=

And, don’t forget to initialize j; or else you would see nothing:

int j = 0; //do this before you enter the loop

You should have received a warning, too, had you not done so.


Result of having 10 UIButtons with the aforementioned modifications:

enter image description here

0

solved How to create 10 UIButtons in round shape in a for loop