접근성 식별자는 자동화 테스트에 사용할 수있는 GUI 객체의 개발자 생성 ID입니다.UIBarButtonItem에서 프로그래밍 방식으로 접근성 식별자 설정
UIBarButtonItem
은 UIAccessibilityIdentification
을 구현하지 않습니다. 그러나 접근성 식별자를 지정할 수있는 가능성이 있습니까?
접근성 식별자는 자동화 테스트에 사용할 수있는 GUI 객체의 개발자 생성 ID입니다.UIBarButtonItem에서 프로그래밍 방식으로 접근성 식별자 설정
UIBarButtonItem
은 UIAccessibilityIdentification
을 구현하지 않습니다. 그러나 접근성 식별자를 지정할 수있는 가능성이 있습니까?
당신은 UIBarButtonItem
하위 클래스 수와 그 서브 클래스에 UIAccessibilityIdentification
프로토콜을 구현한다. 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
에 액세스 할 수 있는지 확인 수 :보기 컨트롤러에서 이제
viewDidLoad
에 가정 해 봅시다
을
- (void)buttonPressed:(id)sender{
if ([sender isKindOfClass:[BarButtonWithAccesibility class]]) {
BarButtonWithAccesibility *theButton = (BarButtonWithAccesibility *)sender;
NSLog(@"My accesibility identifier is: %@", theButton.accessibilityIdentifier);
}
}
희망이 있습니다.
에서 iOS 5의로서 당신은 이런 식으로 작업을 수행 할 수 있습니다
UIBarButtonItem *btn = [[UIBarButtonItem alloc] init...;
btn.accessibilityLabel = @"Label";
접근성 식별자는 레이블과 동일합니까? – Chris
무슨 뜻인지 잘 모르겠지만 시도해 보겠습니다. 기본적으로는 아무 것도 아니므로 직접 설정해야합니다. –
u는 접근성 대신 태그를 사용할 수 있으며 태그에서 객체를 가져올 수도 있습니다. –
을 당신이 프로그래밍 방식으로 다음이 그런 식으로 액세스 할 수있는 여러 UIBarButtonItem
을 만들려면과 같은뿐만 아니라 accessibilityLabel
를 설정하면 그 안에 생성 UIToolbar
이있는 경우 아래에 있음 : -의이 BarButtonWithAccesibility
을 말할 수,
-(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", @"")];
}
하위 클래스 UIBarButtonItem
은 좋은 해결책입니다. 그러나 사용자의 필요에 따라 UIBarButtonItem
이 맞춤 이미지를 사용한다고 가정하고 UIBarButtonItem
의 맞춤 이미지에 accessibilityIdentifier
을 할당하는 것이 더 합리적 일 수 있습니다.
정확하게 필요한 것, 감사합니다! – Chris
기꺼이 도와 드리겠습니다! –
iOS 8에서 문제가 해결 된 것처럼 보였습니다. 이제 'accessibilityIdentifier'도 'UIBarButtonItem'과 함께 사용할 수 있습니다. – fabb