Home > Software design >  How to center and align Text in Slces of a Circle with SwitUI?
How to center and align Text in Slces of a Circle with SwitUI?

Time:11-12

guys I'm new to Swiftui and i try to develop a Spinng Wheel with random choices,So i don't know how to center and align Each Text in Slices of the Wheel. Could you help me to fix it ?

Here is my Code

this is mine

I want to be like this one

CodePudding user response:

You can attach it to a view, so whatever happens to the view, the text will act accordingly to how the spinner is rotated since its a child of the view, and initially keep it in a certain position by rotating it.

CodePudding user response:

SwiftUI has a function transformEffect() that applies a GAffineTransform to a View object (like Text)

In this article from Apple, it applies a rotation around the text's origin:

let transform = CGAffineTransform(rotationAngle: -30 * (.pi / 180))

Text("Projection effect using transforms")
    .transformEffect(transform)
    .border(Color.gray)

You'd need to create a transform that first shifted the origin to your desired point of rotation, rotated the text, and then shifted the origin back. Figuring out transforms makes my head hurt, and I am not very familiar with SwiftUI, but I'll try to find the time to build an example.

  • Related