semanticContentAttribute不再使用默认的UITableViewCells

时间:2018-01-30 15:39:32

标签: swift ios11

我有一个正在运行的应用,我正在尝试添加RTL语言支持。

我使用AppDelegate中的以下行在开始后执行,特别是在didFinishLaunchingWithOptions中。

UIView.appearance().semanticContentAttribute = .forceRightToLeft

它在iOS 10上完美运行,但现在在iOS 11上,默认的tableView单元格的标签仍然是LTR对齐。

current behavior

1 个答案:

答案 0 :(得分:2)

您还应将标签的语义内容属性设置为.forceRightToLeft

编程

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: <your cell ID>, for: indexPath)
    cell.textLabel?.semanticContentAttribute = .forceRightToLeft

    return cell
}

在Interface Builder中

  1. 选择单元格的文本标签

    text label of cell selected

  2. 从右侧工具栏中打开属性检查器(左起第四个图标)。

    Attributes inspector selected

  3. 查看部分中,将语义选项设置为强制从右到左

    Semantic set to Force Right-to-Left

  4. 结果

    cell with right-aligned text