Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
UIAccessibility announcing n of n elements on custom views

When you add a UISegmentedControl to a view, UIAccessibility will focus on it and say:

"(Selected) ItemName Button 1 of 2"
"ItemName Button 2 of 2"

I have a custom control that has UIButtons that toggle similar to a UISegmentedControl. But what I'm trying to figure out is how to get the Voice Over to announce the n of n at the end.

The closest thing that I've found is assigning the .accessibilityTraits = .tabBar on the container. The issue is that it announces:

"ItemName Button Tab 2 of 2"

But to conform to our accessibility guidelines we can't have it announce "tab".

https://developer.apple.com/documentation/uikit/uiaccessibility/uiaccessibilitytraits/1648592-tabbar

Short of just writing a custom accessibilityLabel is there anything within UIAccessibility that can handle this logic?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

  1. Set the container view's accessibilityTraits = .tabBar
  2. Set the container view's accessibilityElements = [button1, button2]
  3. Set each button's accessibilityTraits = .selected or .none when necessary
over 4 years ago · Santiago Trujillo Report

0

I have a custom control that has UIButtons that toggle similar to a UISegmentedControl. But what I'm trying to figure out is how to get the Voice Over to announce the n of n at the end.

  • Put each one of your UIButton elements in the accessibilityElements array of the custom control that acts like a container.
  • By searching a specific element in this array, you will have an index 'x' inside a total amount 'N' of buttons: "item name button x of N".
  • In your UIButton, set accessibilityLabel by inserting the result of the previous research.

enter image description here Here's a kind of logic that should help you reach your purpose with a little bit of code as follows for instance (Xcode 10.2.1, Swift 5.0, iOS 12):

class ButtonsViewController: UIViewController {

    @IBOutlet weak var myCustomContainer: UIView!

    @IBOutlet weak var btn1: UIButton!
    @IBOutlet weak var btn2: UIButton!
    @IBOutlet weak var btn3: UIButton!


    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        myCustomContainer.accessibilityElements = [btn1!, btn2!, btn3!]
        let nbButtons = myCustomContainer.accessibilityElements?.count

        for (index, elt) in (myCustomContainer.accessibilityElements?.enumerated())! {

            let btn = elt as! UIButton
            let btnName = btn.titleLabel?.text

            btn.accessibilityLabel = btnName! + String(index + 1) + " of " + String(describing: nbButtons!)
        }
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!