I can rotate the Text in SwiftUI using rotationEffect but it doesn't rotate the frame. As shown in the image, the text is rotated but the frame is still horizontal. I would like to rotate the frame too so it doesn't take up horizontal space. This is for a Mac app where I'm using HStack to prevent the Text and Circle views from overlapping when the window changes size.
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("Vertical text")
.rotationEffect(.degrees(-90))
Circle()
}
.frame(width: 400, height: 300)
}
}
One suggestion is to use ZStack. This fixes the appearance of the Text view next to the Circle but it doesn't rotate the frame of the Text view. And if ZStack is used with a resizable window then the Circle can overlap the Text view which is why I was trying to use HStack in my original example.
struct ContentView: View {
var body: some View {
ZStack(alignment: .leading) {
Text("Vertical text")
.rotationEffect(.degrees(-90))
Circle()
.padding(.leading)
}
.frame(minWidth: 400, minHeight: 300)
}
}




