6

如何使用 SwiftUI 将 SwiftUI 和其他设计控件旋转 90 度TextButton

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

电流输出:

电流输出

预期输出:

在此处输入图像描述

4

1 回答 1

12

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

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

Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90)))

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

例如,它围绕Text其框架的左下角旋转:

Text("Turtle Rock")
.rotationEffect(Angle(degrees: 90), anchor: .bottomLeading)

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

Text("Turtle Rock")
.rotationEffect(radians: Double.pi / 2)
于 2019-06-07T12:57:43.297 回答