Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda