Hello Apple SwiftUI / Swift Charts Engineering Team,
I am writing to report a layout regression regarding Swift Charts in iOS 27. The anchor property on AxisValueLabel has stopped honoring the .topLeading layout coordinate, whereas it functions perfectly in iOS 26.
Bug Description:
To prevent the first label on a bottom X-axis from clipping past the left screen edge, a .topLeading anchor is applied. In iOS 27, this specific anchor alignment is completely ignored. The chart falls back to a standard top-center alignment, causing the initial boundary label to clip off-screen.
Core Code Snippet to Reproduce:
struct XAxisAnchorBugView: View {
let dates = [
Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 1))!,
Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 2))!
]
var body: some View {
Chart(dates, id: .self) { date in
LineMark(x: .value("Date", date), y: .value("Value", 100))
}
.frame(height: 300)
.padding()
.chartXAxis {
AxisMarks(preset: .aligned, position: .bottom, values: .stride(by: .day, count: 1)) { value in
AxisTick()
let currentAnchor: UnitPoint = {
guard let currentDate = value.as(Date.self) else { return .top }
// BUG: .topLeading layout anchor parameter is completely ignored on iOS 27
return (currentDate == dates.first) ? .topLeading : .top
}()
AxisValueLabel(format: .dateTime.month(.abbreviated).day(), anchor: currentAnchor)
}
}
}
}
Steps to Reproduce:
Render an X-axis with a .bottom position.
Assign anchor: .topLeading strictly to the first axis element's label.
Run on an iOS 26 simulator (the first label anchors its top-left corner correctly, preventing edge clipping).
Run on an iOS 27 simulator (the .topLeading anchor is ignored, reverting to standard top-center alignment).
Expected Behavior:
AxisValueLabel should position its layout bounding box using the .topLeading anchor point when specified.
Actual Behavior:
The layout engine ignores the .topLeading parameter on iOS 27, causing the boundary text to shift left and clip.
Attachments:
I have attached Xcode Simulator screenshots demonstrating this regression:
Best regards,
Soumyajit Das
Thanks for the clear reproduction and for filing FB25282372. Your snippet 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. Swift Charts centers the first label on its tick despite the .topLeading anchor. In the iOS 26.5 simulator, its leading edge sits on the tick, as you describe.
In my tests, this happens only with preset: .aligned. Under that preset, Swift Charts still honors a .topTrailing anchor on the last label. Without the preset, .topLeading works in iOS 27. Please add those details to FB25282372, which is open and under investigation.
Two workarounds leave the plot area as it is. They put the first label's leading edge on the tick in iOS 26.5, iOS 27.0, and iOS 27.2.1.
To keep .aligned, remove the anchor: argument and start the first label with a hidden copy of its text. The label is then twice as wide as its text, so centering it on the tick puts the visible text's leading edge on the tick:
AxisMarks(preset: .aligned, position: .bottom, values: .stride(by: .day, count: 1)) { value in
AxisTick()
AxisValueLabel {
if let date = value.as(Date.self) {
if value.index == 0 {
HStack(spacing: 0) {
Text(date, format: .dateTime.month(.abbreviated).day()).hidden()
Text(date, format: .dateTime.month(.abbreviated).day())
}
} else {
Text(date, format: .dateTime.month(.abbreviated).day())
}
}
}
}
Alternatively, remove preset: .aligned and use AxisValueLabel(format: .dateTime.month(.abbreviated).day(), anchor: value.index == 0 ? .topLeading : .topTrailing). In this chart, without the preset, Swift Charts doesn't draw the last label when it's centered on its tick, which is why it gets .topTrailing. It then ends at its tick instead of centering on it.
Both work around the bug rather than fix it, so keep your report open. The hidden-copy workaround relies on where Swift Charts places a label that has no anchor. The documentation doesn't specify that placement, 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.