Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 428
Aditya Ahuja Avatar asked Sep 03 '19 10:09

Aditya Ahuja


People also ask

How do you make a tableView cell Unselectable?

To completely prevent selection of the UITableViewCell , have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath: . From that method you can return nil if you do not want the row to be selected. This prevents the row from being selected and tableView:didSelectRowAtIndexPath: from being called.


2 Answers

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

like image 115
Aditya Ahuja Avatar answered Sep 28 '22 05:09

Aditya Ahuja


You need to change semanticContentAttribute for the tableView, changing the cell semanticContentAttribute won't do any change.

tableView.semanticContentAttribute = .forceLeftToRight

That should get the job done.

like image 24
AaoIi Avatar answered Sep 28 '22 04:09

AaoIi