Search code examples
iosuitableviewswiftright-to-left

Setting UITableView and section direction/alignment to be RTL (Right to Left)


I created a UITableView in swift, I know I can change the cell direction like this:

cell.textLabel?.textAlignment = NSTextAlignment.Right

But how can I do it to the section? and/or to the entire table?


Solution

  • I followed @ReyGonzales comment and implemented the following tableView:viewForHeaderInSection:

    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        var title: UILabel = UILabel()
    
        title.text = "SomeText"
        title.textAlignment = NSTextAlignment.Right
    
        return title
    }