Search code examples
iosswiftxcodearabic

How can we change the semantic to LTR of a tableview cell when the whole screen is set as RTL?


The screen is in the Arabic language and it's semantic is set right to left. The whole screen consists of a table view with customs cells. I need to change the semantics of one of the cells in the table view to left to right. The cell has two text fields side by side

I have tried cell.countryCodeField.semanticContentAttribute = .forceLeftToRight which is not working

my custom cell

class EditmobileNumberCell: UITableViewCell {

    @IBOutlet weak var mobileNumberField: UITextField!
    @IBOutlet weak var countryCodeField: UITextField!
    @IBOutlet weak var hintLabel: UILabel!
    @IBOutlet weak var mobileNoPlaceHolder: UILabel!
    @IBOutlet weak var backView: UIView!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
            countryCodeField.addRightImage(image: #imageLiteral(resourceName: "icMobileDropdown"), contMode: .bottom)

        mobileNumberField.textAlignment = .left
        countryCodeField.textAlignment = .left
        hintLabel.textAlignment = .left
        mobileNoPlaceHolder.textAlignment = .left
        mobileNumberField.semanticContentAttribute = .forceLeftToRight
        countryCodeField.semanticContentAttribute = .forceLeftToRight
        hintLabel.semanticContentAttribute = .forceLeftToRight
        mobileNoPlaceHolder.semanticContentAttribute = .forceLeftToRight
    }

Any help will be appreciated. Thanks in advance.


Solution

  • Create a view inside the cell and add all the controllers inside it and then use view semanticContentAttribute to forceLeftToRight, in the above case write inside awakeFromNib() -

    backView.semanticContentAttribute = .forceLeftToRight

    This worked for me