Segmented Control: Accessibility Long Press Font Color Issue

Viewed 106

I've been working on an iOS project which requires accessibility for a variety of scenarios and I've run into the following issue.

Setting the text color of the selected segment causes issues when we Long Press at accessibility Font sizes. As the text is white with the dark blue background in the regular UI, when we long press to get the pop out menu (default iOS option at accessibility sizes) it keeps the font colours, but drops the background colours.

I can't seem to find a way to access either the font color or background colours for this pop out menu in accessibility text sizes.

I've searched other questions, and it is very difficult to find information on this feature of iOS.

I'm setting my font Color like this:

let titleTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key.foregroundColor: UIColor(named:"textWhite")!, NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 24)]

segCont.setTitleTextAttributes(titleTextAttributes, for: .selected)

I know the issue is the NSAttributedString.Key.foregroundColor attribute as if I change it from a white to a dark text colour it appears just fine.

I've included an image of the issue for clarity. Any assistance or clarity that anyone can provide would be greatly appreciated.

Segmented Control Accessibility Long press

1 Answers

The solution to this ended up being an extra property backgroundColor in the attributed string. It still isn't perfect, but it's legible and significantly better.

''' let titleTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key.foregroundColor: Theme.segContSelectedText!, NSAttributedString.Key.font: Theme.segContSelectedFont, NSAttributedString.Key.backgroundColor: Theme.segContSelectedTint!]

segCont.setTitleTextAttributes(titleTextAttributes, for: .selected) '''

Related