如何在 SwiftUI 中旋转文本、按钮、矩形?

Hit*_*esh 6 ios swiftui

你怎么能旋转TextButton以及其他设计使用SwiftUI 90度controlls SwiftUI的?

我有意将我的问题建模为这个问题的 SwiftUI 版本:如何在 Swift 中为 UIButton 和 UILabel 旋转文本?

电流输出:

电流输出

预期输出:

在此处输入图片说明

RPa*_*l99 10

使用任何一种.rotationEffect()方法View顺时针旋转,包括ButtonText

例如,它绕Text其原点(其框架的中心)旋转:

Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90)))
Run Code Online (Sandbox Code Playgroud)

使用带有锚点参数的重载方法围绕不同的点旋转。

例如,这围绕Text其框架的左下点旋转:

Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90), anchor: .bottomLeading)
Run Code Online (Sandbox Code Playgroud)

您还可以使用弧度进行旋转:

Text("Turtle Rock")
.rotationEffect(radians: Double.pi / 2)
Run Code Online (Sandbox Code Playgroud)