繁体   English   中英

将UITableView方向更改为从右到左

[英]Change UITableView direction to Right-to-Left

我开发了一个iOS应用程序,我的母语是波斯语(一种从右到左的语言)。 如何在iOS编程中将UITableView方向更改为从右到左?

具有RTL方向的UITableView具有:

  • 图标在右边
  • TableCell详细信息和按钮位于左侧
  • TableView页眉和页脚是右对齐的

像这样 :

在此输入图像描述

是否有任何UI或编程方式来执行此操作?

在Swift 3上试试吧

tableView.semanticContentAttribute = .forceRightToLeft

或者在StoryBoard Cell属性(Semantic dropdown)中选择“Force Right-to-Left”

在此输入图像描述

我知道它会自iOS8以来自动改为从右到左。

您也可以尝试这样做

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = myTableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell

    cell.textLabel?.textAlignment = .Right

    cell.textLabel?.text = goalsArray[indexPath.row]

    return cell
}

使用NSLayoutAttributeLeadingNSLayoutAttributeTrailing而不是NSLayoutAttributeLeftNSLayoutAttributeRight构建视图的约束。

您的视图的方向将与您应用的语言方向相同。

在此输入图像描述

对我来说这种方式很有效

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier)! as UITableViewCell

    //cell.myView.backgroundColor = self.colors[indexPath.row]
    cell.textLabel?.text =
    "\((self.FAQs?[indexPath.row].Question)!)"

    cell.textLabel?.textAlignment = .right

    return cell
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM