Setting accessibility identifier programmatically on UIBarButtonItem

后端 未结 4 1885
轻奢々
轻奢々 2021-02-12 08:26

The accessibility identifier is a developer generated ID for GUI objects, which can be used for automation tests.

A UIBarButtonItem does not implement

4条回答
  •  梦毁少年i
    2021-02-12 08:50

    If you have UIToolbar created inside that if you want to create multiple UIBarButtonItem programatically then it can be accessed like that and set accessibilityLabel as well like that below:-

        -(void)viewDidAppear:(BOOL)animated
        {
            UIBarButtonItem *infoButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"info" style:UIBarButtonItemStyleBordered  target:self action:@selector(infoButtonClicked)];
            [self.customToolBar setItems:[NSArray arrayWithObject:infoButtonItem]];
    //Here if you have muliple you can loop through it 
           UIView *view = (UIView*)[self.customToolBar.items objectAtIndex:0];
        [view setAccessibilityLabel:NSLocalizedString(@"Test", @"")];
        }
    

提交回复
热议问题