Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - how to change text alignment of label in Toggle?

Code for Toggle in SwiftUI is this:

Toggle(isOn: $vibrateOnRing) {
    Text("Vibrate on Ring")
}

This will produce a toggle button with text label looking like this:

Vibrate on Ring | [--empty space--] | Toggle

I need a right-aligned text label, like this:

[--empty space--] | Vibrate on Ring | Toggle

How to do it in SwiftUI?

like image 731
mallow Avatar asked Jan 25 '23 22:01

mallow


1 Answers

Here it is

demo

Toggle(isOn: $vibrateOnRing) {
    Text("Vibrate on Ring")
      .frame(maxWidth: .infinity, alignment: .trailing)
}
like image 74
Asperi Avatar answered Jan 27 '23 13:01

Asperi