This question already has an answer here:
I am attempting to plot circular buttons in a ring like this.
I have 6 UI buttons which all have a corner-radius of 360 degrees, what I am attempting to do in Swift is plot them equally around a central button/point just like the image above. Each circle is equally spaced from its neighbour. What is the best way of achieving this functionality? Should I create a bezier curve and then use math to plot the buttons around said curve or is there another way which you would suggest?
A side note is that I am not looking for a radial menu of any kind there is no animation required. I am just trying to plot my existing UI Buttons in the format above.
Thanks!
You don't need a bezierpath for that, just a bit of calculation.
I am not a math genius or something so I took an already answered question and changed it to my needs.
Use an array of UIView so you are flexible. If you want to add the buttons from code, just uncomment (1). If you want the buttons to rotate according to their rotation around the center, uncomment (2).
Btw it is not necessary to add 360 degree cornerradius to the buttons for a round shape. Please have a read on the documentation here.
Happy coding!
I would suggest using math (trigonometry) to compute the horizontal and vertical offsets from the center button and then use layout anchors to position the buttons.
Here is a self contained example:
Notes:
If you don't need the center button, just set up the buttons around
self.view
:or around an arbitrary point:
UIView
as the center instead of a point is more flexible because you can dynamically move thatUIView
and the buttons will follow.Here it is running in the simulator: