How to Align an image to the right corner in list row using SwiftUI?

Viewed 2972

I'm trying to align an image to the right size of a list row in Swift/SwiftUI.

List {
    Image(systemName: "pencil")
}

I've tried adding several different alignment tags but none seem to work. Any help would be greatly appreciated :)

2 Answers

Put it in a HStack and add a spacer.

List {
     HStack {
           Spacer()
           Image(systemName: "pencil")
     }
}

I assume you wanted this (tested with Xcode 12.1 / iOS 14.1):

demo

List {
    Image(systemName: "pencil")
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
        .listRowInsets(EdgeInsets())
}
Related