How to skip accessibility focus on one bar button item and keep focus on other bar button items of the toolbar
Asked Answered
M

1

8

I have a toolbar , I'd like to skip the title button when accessibility is turned on.

I can skip accessibility for the whole tool bar using accessibilityElementsHidden.

but I just want to skip the accessibility focus of title bar button.

I tried disabling the title button's accessibility individually.

But it's not working.

So I set the AccessibilityElements property , it's skipping the title bar and reading out the DONE button on right side. But there's no individual focus on that DONE button at all. The focus is missing for individual bar button items when I use AccessibilityElements.

Update:

I have added an observer here

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

Here is the observer

 [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(beginEditingHandler:) name:UITextFieldTextDidBeginEditingNotification object:nil];

Here is how I'm managing the accessibility items

  - (void)beginEditingHandler:(NSNotification *)notification {
    UIResponder *responder = notification.object;
    IQToolbar *inputAccessoryView = responder.inputAccessoryView;
    if (inputAccessoryView) {
        if ([inputAccessoryView isKindOfClass:[IQToolbar class]]){
            NSMutableArray *arrAccessibilityItems = [[NSMutableArray alloc]init];
            if(inputAccessoryView.previousBarButton){
                if(!inputAccessoryView.previousBarButton)
                [arrAccessibilityItems addObject:inputAccessoryView.previousBarButton];
            }
            if(inputAccessoryView.nextBarButton){
                if(!inputAccessoryView.nextBarButton.isHidden)
                [arrAccessibilityItems addObject:inputAccessoryView.nextBarButton];
            }
            if(inputAccessoryView.titleBarButton){
                IQTitleBarButtonItem *titleBtn= inputAccessoryView.titleBarButton;
                if(titleBtn.title.length>0){
                    [arrAccessibilityItems addObject:inputAccessoryView.titleBarButton];
                }
            }
            if(inputAccessoryView.doneBarButton){
                [arrAccessibilityItems addObject:inputAccessoryView.nextBarButton];
            }
            [inputAccessoryView setAccessibilityElements:arrAccessibilityItems];

        }
    }
}

The problem is this read out as whole tool bar rather than a bar item by bar item.

Merilee answered 7/10, 2023 at 23:36 Comment(2)
Your question is lacking any relevant details. Please show how you setup your toolbar. Clearly show what code you have tried and what element exactly you are trying to skip.Lockwood
@Lockwood - I have added code snippetMerilee
P
1

IQToolbar sets up a title button as follows:

    @objc open var titleBarButton: IQTitleBarButtonItem {
        get {
            if privateTitleBarButton == nil {
                privateTitleBarButton = IQTitleBarButtonItem(title: nil)
                privateTitleBarButton?.accessibilityLabel = "Title"
                privateTitleBarButton?.accessibilityIdentifier = privateTitleBarButton?.accessibilityLabel
            }
            return privateTitleBarButton!
        }

        set (newValue) {
            privateTitleBarButton = newValue
        }
    }

You'll have to subclass IQToolbar and override titleBarButton as follows:

open class MyToolbar: IQToolbar {
    open var titleBarButton: IQTitleBarButtonItem {
        get {
            let titleBarButton = super.titleBarButton
            titleBarButton.customView.subviews.first?.isAccessibilityElement = false
            return titleBarButton
        }
        set (newValue) {
            super.titleBarButton = newValue
        }
    }
}
Pedology answered 11/11, 2023 at 21:55 Comment(2)
the problem is with the accessibility in the tool bar ? Any ideas how to fix it ?Merilee
@Merilee Did you try my answer? Does it solve your issue? If yes, please mark answer as accepted.Pedology

© 2022 - 2025 — McMap. All rights reserved.