TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Is there a way to set the alignment in a TableColumn in SwiftUI?

Forums > macOS

Hi. This seems odd. I've got a column in a Table that is going to be displaying currency amounts and I'd like it to be aligned to the trailing edge. Is there any way to do this in SwiftUI? I thought maybe there might be something when setting up TableColumn() but it seems to lack an alignment parameter. I thought maybe using something like .multilineTextAlignment(.trailing) might work below the Text() I'm putting into the cell, but it seems to be ignored.


Just figured out that I could wrap my contents in an HStack and then use a Spacer() before my Text() to push my column content to the right side. In the absense of some other preferred way, this is at least working fine.


The .multilineTextAlignment(.trailing) will align the text if it goes over a few lines to the trailing edge so if your Text is on one line you will not see anything with this modifier.



I've used the usual frame settings:

TableColumn("Name") { file in
    .frame(maxWidth: .infinity, alignment: .trailing)


I'm working on a project in SwiftUI, and I'm facing a bit of a challenge with aligning currency amounts in a TableColumn. I want the amounts to be aligned to the trailing edge, giving the table a neat appearance. It seems like there's no direct way to set the alignment within the TableColumn initializer – there's no alignment parameter available. I tried using .multilineTextAlignment(.trailing) below the Text() view that holds the currency data in each cell, hoping it would work, but unfortunately, it's not having the desired effect.


@Mathias seeks guidance, but provides written clues only:

I tried using .multilineTextAlignment(.trailing) below the Text()

First, welcome to HackingWithSwift forums. There are many here who have gone down the learning path and are willing to help answer questions, even providing code examples.

To help us help you, please provide some code snips of what you tried, and provide comments on what didn't work. Perhaps we can help you from there. Code snips have the added benefit of allowing others to learn from your coding techniques to incorporate into their solutions.

Keep coding!


Replace the Text() view with:

HStack {

I suggest you read the Apple reference for TableColumn. It says the content: parameter should be a type that conforms to the View protocol. This means it can be a View composed of "child" views such as my example. This is a very common pattern in SwiftUI.



Seems like we have a new solution to this, using TableColumnAlignment. However - currently in beta and only available on iOS 17.0+, macOS 14.0+, etc.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.