To center a view in SwiftUI, you can use the .frame
modifier with the alignment
parameter set to .center
. Here's an example:
main.swift173 chars7 lines
In this example, we're using the .frame
modifier on the Text
view and setting the alignment
parameter to .center
. This will center the text horizontally and vertically within its parent view.
You can adjust the maxWidth
and maxHeight
parameters to control the size of the view. If you set them to .infinity
, the view will expand to fill its parent view.
gistlibby LogSnag