简体   繁体   中英

Change UITableView direction to Right-to-Left

I develop an iOS application and my native language is Persian (a Right-to-Left language). How can I change UITableView direction to right-to-left in iOS programming?

A UITableView with RTL direction has:

  • Icons are at right
  • TableCell detail and button are at left
  • TableView header and footer are right-aligned

like this :

在此输入图像描述

Is there any UI or programming way to do this?

Try this on Swift 3

tableView.semanticContentAttribute = .forceRightToLeft

or in StoryBoard Cell properties (Semantic dropdown) select "Force Right-To-Left"

在此输入图像描述

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

You can try to do this as well

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
}

Build your view's constraints with NSLayoutAttributeLeading and NSLayoutAttributeTrailing instead of NSLayoutAttributeLeft and NSLayoutAttributeRight .

Your view's Direction will be the same with your app's language Direction.

在此输入图像描述

for me this way worked

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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