Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

swiftui

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 :)

like image 390
Lemon Avatar asked Dec 22 '22 16:12

Lemon


2 Answers

Put it in a HStack and add a spacer.

List {
     HStack {
           Spacer()
           Image(systemName: "pencil")
     }
}
like image 57
Wesley Brito Avatar answered May 25 '23 10:05

Wesley Brito


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())
}
like image 39
Asperi Avatar answered May 25 '23 11:05

Asperi