How to Rotate Text in SwiftUI?

SwiftUI Text – Rotate

To rotate text in Text view, call rotationEffect() method on this Text view, and provide the amount of rotation in degrees or radians.

Example

In the following example, we have a Text view and we will rotate the Text by 90 degrees.

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World!")
            .font(.title)
            .rotationEffect(.degrees(90))
    }
}

Screenshot

SwiftUI Text - Rotate by 90 degrees

The rotation happens in clockwise direction.

Rotate by 180 degrees

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World!")
            .font(.title)
            .rotationEffect(.degrees(180))
    }
}

Screenshot

SwiftUI Text - Rotate by 180 degrees

Rotate by 180 degrees

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World!")
            .font(.title)
            .rotationEffect(.degrees(45))
    }
}

Screenshot

SwiftUI Text - Rotate by 45 degrees

Rotate by 180 degrees

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World!")
            .font(.title)
            .rotationEffect(.degrees(45))
    }
}

Rotate by PI radians

We can also give angle in radians. In the following example, we will rotate the text by PI radians.

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World!")
            .font(.title)
            .rotationEffect(.radians(.pi))
    }
}

Screenshot

SwiftUI Text - Rotate by PI radians

Summary

Summarising this SwiftUI Tutorial, we learned how to rotate text in Text view.