如何使用SwiftUI将Text
,Button
和SwiftUI的其他设计控件旋转90度?
我有意将我的问题建模为这个问题的SwiftUI版本:How can you rotate text for UIButton and UILabel in Swift?
当前输出:
预期输出:
如何使用SwiftUI将Text
,Button
和SwiftUI的其他设计控件旋转90度?
我有意将我的问题建模为这个问题的SwiftUI版本:How can you rotate text for UIButton and UILabel in Swift?
当前输出:
预期输出:
2条答案
按热度按时间pwuypxnk1#
使用任何一个
.rotationEffect()
方法顺时针旋转任何View
,包括Button
和Text
。例如,这会使
Text
绕其原点(其框架的中心)旋转:使用带锚参数的重载方法绕不同的点旋转。
例如,这将围绕其帧的左下角点旋转
Text
:也可以使用弧度进行旋转:
8wigbo562#
要做任何类型的(复杂的)旋转,使用3D作为
.rotation3DEffect(.degrees(45), axis: (x: 0.5, y: 0, z: 0))
(这将是星球大战学分效果)。这两个应该是等价的:Text("Turtle Rock").rotationEffect(Angle(degrees: 90)))
和Text("Turtle Rock").rotation3DEffect(.degrees(90), axis: (x: 0, y: 0, z: 1))