Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

semanticContentAttribute is not working anymore with default UITableViewCells

Tags:

swift

ios11

I have a running app, and I'm trying to add RTL language support.

I use the line below in my AppDelegate to execute after start, specifically in didFinishLaunchingWithOptions.

UIView.appearance().semanticContentAttribute = .forceRightToLeft

It was working perfectly on iOS 10, but now on iOS 11, the default tableView cell's labels are still aligned LTR.

current behavior

like image 338
Ahmed Fathi Avatar asked Oct 27 '25 08:10

Ahmed Fathi


1 Answers

You should set the label's semantic content attribute to .forceRightToLeft as well.

Programmatically

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: <your cell ID>, for: indexPath)
    cell.textLabel?.semanticContentAttribute = .forceRightToLeft

    return cell
}

In Interface Builder

  1. Select the text label of the cell.

    text label of cell selected

  2. Open the Attributes inspector (the fourth icon from the left) from the toolbar on the right.

    Attributes inspector selected

  3. In the View section, set the Semantic option to Force Right-to-Left.

    Semantic set to Force Right-to-Left

Result

cell with right-aligned text

like image 198
Tamás Sengel Avatar answered Oct 29 '25 00:10

Tamás Sengel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!