Установка accessibilityLabel для текста заголовка UITableView - PullRequest
1 голос
/ 25 марта 2020

Я пытаюсь найти способ установить accessibilityLabel для текста заголовка моего табличного представления.

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {        
    return @"Table View Header";
}

В моем случае моя метка доступности отличается от возвращенного текста заголовка табличного представления.

Ответы [ 2 ]

1 голос
/ 25 марта 2020

Кроме того, вы также можете использовать свойство textLabel UITableViewHeaderFooterView.

Пример кода:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] init];
    headerView.textLabel.text = @"tableview header";
    headerView.isAccessibilityElement = YES;
    headerView.accessibilityLabel = @"tableview header for accessibility";

    return headerView;
}
1 голос
/ 25 марта 2020

Чтобы установить свойство accessibilityLabel, напишите текст в определении самого представления заголовка , как я это сделал во фрагменте кода ниже, добавив элемент доступности:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    CGRect headerViewFrame = CGRectMake(0.0, 0.0, tableView.frame.size.width, 44.0);
    UIView * headerView = [[UIView alloc] initWithFrame:headerViewFrame];

    UILabel * headerViewLabel = [[UILabel alloc] initWithFrame:headerViewFrame];
    headerViewLabel.text = @"Table View Header";
    [headerView addSubview: headerViewLabel];

    UIAccessibilityElement * a11yHeader = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:headerView];
    a11yHeader.accessibilityFrameInContainerSpace = headerView.frame;
    a11yHeader.isAccessibilityElement = YES;
    a11yHeader.accessibilityLabel = @"my new header text for accessibility";
    a11yHeader.accessibilityTraits = UIAccessibilityTraitHeader;

    headerView.accessibilityElements = @[a11yHeader];

    return headerView;
}

Попробуйте это и адаптируйте к своему приложению.

Не так просто go вернуться к Obj C ?, но теперь вы можете установить accessibilityLabel для текста заголовка UITableView с помощью следуя этому обоснованию. ???

...