Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left and right padding (not leading and trailing) in SwiftUI

A padding modifier in SwiftUI takes an EdgeInsets, eg

.padding(.leading, 8)

However, there are only leading and trailing EdgeInsets, and not left and right. This presents a problem because not everything in RTL languages should necessarily be reversed from the way it's displayed in LTR languages.

Is there a way to achieve the same or similar effect as the padding modifier, which forces the padding to be on left or right side, regardless of directionality of the language?

like image 794
Steve M Avatar asked Sep 10 '25 17:09

Steve M


1 Answers

struct ContentView: View {
var body: some View {
    Text("Hello, SwiftUI!")
        .padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20)) // Apply custom padding values
}

}

like image 145
Divyansh Chaudhary Avatar answered Sep 12 '25 07:09

Divyansh Chaudhary