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

谁说胖子不能爱 提交于 2021-02-16 20:10:32

问题


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?


回答1:


Here it is

Toggle(isOn: $vibrateOnRing) {
    Text("Vibrate on Ring")
      .frame(maxWidth: .infinity, alignment: .trailing)
}


来源:https://stackoverflow.com/questions/62698587/swiftui-how-to-change-text-alignment-of-label-in-toggle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!