• Status: Solved
• Priority: Medium
• Security: Public
• Views: 577

# How do I display 10 buttons in a circle in objective c using for loop?

Need a solution and please explain each line if you could. Many thanks.
0
charmingduck
• 4
• 4
2 Solutions

Senior iOS DeveloperCommented:
Excuse me; what do you mean by displaying 10 buttons in a circle!?
0

Author Commented:
in a round shape
0

Author Commented:
like putting 10 apples around a round table.
0

Senior iOS DeveloperCommented:
For doing that you have to calculate the coordinates of 10 points placed on a circle with equal spaces. This is a calculus problem (finding 10 points on equation X^2 + Y^2 = K where the distance between each neighbor points is exactly the same)
iOS does not have a method which finds the points for you. You have to do it manually.
You may also try to do this in Interface Builder but unfortunately you cannot determine the precise position of each button.
0

Author Commented:
do you know how to do it with a for loop?
0

Senior iOS DeveloperCommented:
As I said you have to first calculate 10 points coordinates. afterwards the for loop is quite easy then.
0

Author Commented:
I think there is a smart way to draw this circle in code rather than entering the cords manually?
0

Senior iOS DeveloperCommented:
No I did not suggest you to calculate the coordinates manually. I meant you should write a function that take e.g. 3 parameters: CIRCLE_CENTER, CIRCLE_RADIUS, NO_OF_POINTS which utilizes a calculus-based algorithm to calculate the coordination of each point then return all those in an array. Afterwards you will write a for-loop to create 10 buttons by using the coordinates in that array.
0

## Featured Post

• 4
• 4
Tackle projects and never again get stuck behind a technical roadblock.