To apply padding using SwiftUI in Swift, you can use the .padding()
modifier on any SwiftUI View.
Here's an example:
main.swift37 chars3 lines
This will add a default padding of 10 points
to all sides of the Text
view.
You can also customize the amount of padding on each side by passing in the desired padding amount as a parameter:
main.swift101 chars5 lines
In this example, the .padding(.top, 20)
adds 20 points
of padding to the top of the view, .padding(.horizontal, 30)
adds 30 points
of padding to the left and right sides of the view, and .padding(.bottom, 10)
adds 10 points
of padding to the bottom of the view.
You can also use the shorthand method by passing in the padding amounts in the order top, leading, bottom, trailing
:
main.swift51 chars3 lines
In this example, 20
is the padding amount on the top, 30
is the padding amount on the left side, 10
is the padding amount on the bottom, and 30
is the padding amount on the right side.
gistlibby LogSnag