Hello Apple SwiftUI / Swift Charts Engineering Team,
I am writing to report a layout regression regarding Swift Charts in iOS 27. The multiLabelAlignment property on AxisValueLabel has stopped working as expected, whereas it functions perfectly in iOS 26.
Bug Description:
When configuring custom string values within AxisMarks using AxisValueLabel with multiLabelAlignment: .trailing, the alignment configuration is completely ignored on iOS 27. Labels fail to align text properly to the trailing edge, causing rendering layout issues for multi-line or custom text labels on the Y-axis. This exact same implementation compiles and aligns correctly on iOS 26.
Code Snippet to Reproduce:
swift
struct YAxisAlignmentBugView: View {
// data points to render the chart frame
let data = [(date: Date(), revenue: 3000.0), (date: Date().addingTimeInterval(10000), revenue: 4000.0)]
var body: some View {
Chart(data, id: .date) { item in
LineMark(x: .value("Date", item.date), y: .value("Revenue", item.revenue))
}
.frame(height: 300)
.padding()
.chartYAxis {
AxisMarks(preset: .aligned, position: .trailing, values: [12.0, 600.0, 3000.0, 6000.0]) { value in
if let revenue = value.as(Double.self) {
// BUG: multiLabelAlignment: .trailing is completely ignored on iOS 27
AxisValueLabel("y-(Int(revenue))", anchor: .leading, multiLabelAlignment: .trailing)
}
}
}
}
}
Steps to Reproduce:
Render a Swift Chart containing a .chartYAxis configuration with position: .trailing.
Pass a string directly using AxisValueLabel(customText, anchor: .leading, multiLabelAlignment: .trailing).
Run the application on an iOS 26 simulator (text aligns properly to the trailing edge).
Run the identical application code on an iOS 27 simulator.
Expected Behavior:
The text inside the AxisValueLabel should honor the multiLabelAlignment: .trailing parameter and align the text strings flush right.
Actual Behavior:
The multiLabelAlignment layout modifier is ignored on iOS 27, resulting in unexpected default left-alignment of the text strings.
Attachments:
I have attached screenshots from the Xcode Simulator demonstrating the regression:
Please let me know if you need any further diagnostic details.
Best regards,
Soumyajit Das
Thanks for confirming the labels are single-line. That rules out text alignment within a label as the cause. Your axis code showed the problem on the first run, on an iPhone 18 Pro Max running iOS 27.2.1 and in the iOS 27.0 simulator. The labels line up flush left. In the iOS 26.5 simulator, they line up flush right, as you describe.
Unlike the anchor problem in your other thread, Regression: AxisValueLabel anchor parameter ignores .topLeading on iOS 27, this one doesn't depend on .aligned. In my tests, iOS 27 also ignored multiLabelAlignment: .trailing with the default preset, without an anchor, and with the content initializer. Please add those details to FB25282320, which is open and under investigation.
To work around it, make every label as wide as the widest one, and align the text inside it. Stack hidden copies of all the labels behind the visible one in a trailing-aligned ZStack:
let values: [Double] = [12, 600, 3000, 6000]
// In body:
.chartYAxis {
AxisMarks(preset: .aligned, position: .trailing, values: values) { value in
if let revenue = value.as(Double.self) {
AxisValueLabel(anchor: .leading) {
ZStack(alignment: .trailing) {
ForEach(values, id: \.self) { Text("y-\(Int($0))").hidden() }
Text("y-\(Int(revenue))")
}
}
}
}
}
Build the hidden copies the same way as the visible text, so their widths match. String interpolation in Text formats the number for the locale, as in "y-6,000".
In iOS 26.5, iOS 27.0, and iOS 27.2.1, this lines the labels up flush right, with or without .aligned. It works around the bug rather than fixing it, so keep your report open. It relies on how Swift Charts lays out label content, which the documentation doesn't specify, so check it when you test new releases.
Please continue to test your software in release and pre-release versions of system software made available to you through your developer.apple.com account. When you do, add details about that into your bug report to keep it up to date. Please see developer.apple.com/download.