2013-12-12 13 views
18

पर प्रोग्राम के रूप में पहुँच पहचानकर्ता एक डेवलपर जीयूआई वस्तुओं, जो स्वचालन परीक्षण के लिए इस्तेमाल किया जा सकता के लिए आईडी जेनरेट किया गया है।स्थापना पहुंच पहचानकर्ता UIBarButtonItem

एक UIBarButtonItemUIAccessibilityIdentification को लागू नहीं करता है। हालांकि क्या कोई संभावना है कि मैं एक अभिगम्यता पहचानकर्ता असाइन कर सकता हूं? आप UIToolbar कि अंदर बनाया आप प्रोग्राम के तो ऐसा पहुँचा जा सकता है कई UIBarButtonItem बनाना चाहते हैं और इस तरह के रूप में अच्छी तरह accessibilityLabel सेट अगर है, तो

UIBarButtonItem *btn = [[UIBarButtonItem alloc] init...; 
btn.accessibilityLabel = @"Label"; 

उत्तर

13

आप UIBarButtonItem उपवर्ग और कहा कि उपवर्ग में UIAccessibilityIdentification प्रोटोकॉल को लागू कर सकता है, मान लें कि BarButtonWithAccesibility सुविधा देता है।

BarButtonWithAccesibility.h में:

@interface BarButtonWithAccesibility : UIBarButtonItem<UIAccessibilityIdentification> 

@property(nonatomic, copy) NSString *accessibilityIdentifier NS_AVAILABLE_IOS(5_0); 

इस प्रोटोकॉल का पालन कर accessibilityIdentifier संपत्ति को परिभाषित करने के लिए केवल (सख्त) की आवश्यकता।

#import "BarButtonWithAccesibility.h" 

- (void)viewDidLoad{ 

    [super viewDidLoad]; 

    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 

    BarButtonWithAccesibility *myBarButton = [[BarButtonWithAccesibility alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonPressed:)]; 
    myBarButton.accessibilityIdentifier = @"I am a test button!"; 

    toolbar.items = [[NSArray alloc] initWithObjects:myBarButton, nil]; 
    [self.view addSubview:toolbar]; 
} 

और buttonPressed: भीतर आप सत्यापित कर सकता है कि आप accessibilityIdentifier की पहुंच है:

अब आपके विचार नियंत्रक में, आप एक UIToolbar की स्थापना की और अपने subclassed UIBarButtonItem जोड़ सकता है के viewDidLoad में मान लीजिए,

- (void)buttonPressed:(id)sender{ 
    if ([sender isKindOfClass:[BarButtonWithAccesibility class]]) { 
     BarButtonWithAccesibility *theButton = (BarButtonWithAccesibility *)sender; 
     NSLog(@"My accesibility identifier is: %@", theButton.accessibilityIdentifier); 
    } 
} 

आशा इस मदद करता है।

+0

बिल्कुल मुझे क्या चाहिए, धन्यवाद! – Chris

+0

खुशी है कि मैं मदद कर सकता हूँ! –

+5

ऐसा लगता है कि आईओएस 8 ने इस मुद्दे को ठीक किया है, और 'accessibilityIdentifier' का उपयोग अब' UIBarButtonItem' के साथ भी किया जा सकता है। – fabb

4

iOS 5 के रूप में आप इस तरह यह कर सकते हैं नीचे है कि: -

-(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", @"")]; 
    } 
+0

क्या अभिगम्यता पहचानकर्ता लेबल के समान है? – Chris

+0

सुनिश्चित नहीं है कि आपका क्या मतलब है, लेकिन मैं इसे आज़मा दूंगा: डिफ़ॉल्ट रूप से यह शून्य है, आपको इसे स्वयं सेट करना होगा। –

+0

आप टैग के बजाय एक्सेसिबिलिटी का उपयोग कर सकते हैं और टैग से ऑब्जेक्ट भी प्राप्त कर सकते हैं। –

2

उपclassing UIBarButtonItem एक अच्छा समाधान है। आपकी जरूरतों के आधार पर, आपके UIBarButtonItem की कस्टम छवि में UIBarButtonItem कस्टम छवि का उपयोग करने के लिए, accessibilityIdentifier को बस असाइन करने के लिए और अधिक समझ हो सकती है।

संबंधित मुद्दे