How to Left Align Image in SwiftUI?

SwiftUI – Left Align Image

To left align Image in its frame, set the frame alignment of this Image to leading edge.

The following code shows how to left align Image.

    .frame(maxWidth: .infinity, alignment: .leading)


In the following example, we display an Image view, and set its alignment to leading edge, or in other words, left.


import SwiftUI

struct ContentView: View {
    var body: some View {
                .frame(width: 100, height: 100)
                .frame(maxWidth: .infinity, alignment: .leading)

The first .frame() modifier is for resizing the image to 100×100. The second .frame() modifier sets the width of the Image frame to the maximum available width and aligns the Image to the leading edge.


SwiftUI - Left Align Image

The border around the image depicts the frame of the Image, and the alignment of the Image to the left, or leading edge.


Summarising this SwiftUI Tutorial, we learned how to left align Image in SwiftUI.