首页 > 解决方案 > 为 UITableView 标题文本设置 accessibilityLabel

问题描述

我正在尝试找到一种方法来设置accessibilityLabel我的 tableview 的标题文本。

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

就我而言,我的可访问性标签与返回的 tableview 的标题文本不同。

标签: iosobjective-cuitableviewuiaccessibility

解决方案


或者,您也可以使用 的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;
}

推荐阅读