How can you rotate Text
, Button
and other design controlls of SwiftUI by 90 degrees using SwiftUI?
I am intentionally modeling my question as a SwiftUI version of this one: How can you rotate text for UIButton and UILabel in Swift?
Current output:
Expected output:
Use any one of the . rotationEffect() methods to rotate any View clockwise, including Button and Text . Use the overloaded method with an anchor argument to rotate around a different point.
Go to the preview pane and select the live view button. Drag the slider to rotate the image.
SwiftUI's rotation3DEffect() modifier lets us rotate views in 3D space to create beautiful effects in almost no code. It accepts two parameters: what angle to rotate (in degrees or radians), plus a tuple containing the X, Y, and Z axis around which to perform the rotation.
Use any one of the .rotationEffect()
methods to rotate any View
clockwise, including Button
and Text
.
For example, this rotates Text
about its origin (the center of its frame):
Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90)))
Use the overloaded method with an anchor argument to rotate around a different point.
For example, this rotates Text
about the bottom left point of its frame:
Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90), anchor: .bottomLeading)
You can also use radians for rotation:
Text("Turtle Rock")
.rotationEffect(radians: Double.pi / 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With