Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda