आप 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);
}
}
आशा इस मदद करता है।
स्रोत
2013-12-25 19:13:19
बिल्कुल मुझे क्या चाहिए, धन्यवाद! – Chris
खुशी है कि मैं मदद कर सकता हूँ! –
ऐसा लगता है कि आईओएस 8 ने इस मुद्दे को ठीक किया है, और 'accessibilityIdentifier' का उपयोग अब' UIBarButtonItem' के साथ भी किया जा सकता है। – fabb