Skip to content

Add support for attributed label, value, hint in legend#288

Open
meherkasam-square wants to merge 4 commits into
mainfrom
meher/string-attrs
Open

Add support for attributed label, value, hint in legend#288
meherkasam-square wants to merge 4 commits into
mainfrom
meher/string-attrs

Conversation

@meherkasam-square

@meherkasam-square meherkasam-square commented Jan 14, 2026

Copy link
Copy Markdown
Collaborator

This PR adds support for the use of attributed strings in accessibility properties such as:

The following keys are now supported:

UIKit Demo

SwiftUI

Additionally, heading levels in SwiftUI that are configured via .accessibilityHeading now directly appear next to the label.

@meherkasam-square meherkasam-square self-assigned this Jan 14, 2026
@meherkasam meherkasam force-pushed the meher/string-attrs branch 2 times, most recently from 6f954f7 to 752423e Compare January 14, 2026 04:40
let activationPoint = element.object.accessibilityActivationPoint

// Get heading level via Key-Value Coding (set by SwiftUI's .accessibilityHeading() modifier)
let headingLevel = element.object.value(forKey: "accessibilityHeadingLevel") as? Int

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this distinct from UIAccessibilityTextAttributeHeadingLevel attribute?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I discovered yesterday that they are different. This path handles the more straightforward approach in which one might add a heading level in SwiftUI.

// Sort attributes by key name to ensure consistent ordering across test runs
let sortedAttributes = attributes.sorted { $0.key.rawValue < $1.key.rawValue }

for (key, value) in sortedAttributes {

@RoyalPineapple RoyalPineapple Jan 14, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this list of if statements be a loop of some sort?

@meherkasam-square meherkasam-square marked this pull request as ready for review January 14, 2026 18:16
static let iconToDescriptionSpacing: CGFloat = 4

static let headerFont: UIFont = .italicSystemFont(ofSize: 11)
static let font: UIFont = .monospacedSystemFont(ofSize: 10, weight: .regular)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern with this PR is making this monospace. Nothing else is monospace in the legend, right? Why change it from the default font?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants