History
Loading...
Loading...
October 3, 2025
LabeledContent instead of custom HStack/VStack combinations when displaying label-value pairs. It automatically handles accessibility, semantic structure, and adapts to system settings like Dynamic Type without additional configuration.LabeledContent provides semantic structure for label-value pairs, automatically handling accessibility labels, VoiceOver navigation, and responsive layout. It supports both string values and custom content through ViewBuilder, making it perfect for forms and detail views.
struct UserProfileView: View {
let user: User
var body: some View {
Form {
Section("Account Details") {
LabeledContent("Email", value: user.email)
LabeledContent("Member Since", value: user.joinDate, format: .dateTime.year().month(.wide))
LabeledContent("Posts") {
Text("\(user.postCount)")
.foregroundStyle(.secondary)
.font(.monospacedDigit(.body)())
}
LabeledContent("Status") {
Label(user.status.rawValue, systemImage: user.statusIcon)
.foregroundStyle(user.statusColor)
}
}
}
}
}This approach ensures better accessibility out of the box, reduces custom layout code, and provides consistent visual hierarchy. The semantic structure helps screen readers understand the relationship between labels and values, while automatic Dynamic Type support ensures content remains readable across all text sizes.