Dorad
Dorad

Reputation: 3713

table cell views are not right aligned

I am trying to right-align my table cells.

simulator

I have set 'Semantic' property to 'Force Right-to-Left' value through the whole visual tree.

Desired layout:

Desired state

Visual tree:

Visual tree

There aren't any visual definitions in code...

EDIT:

After @dirtydanee suggestion:

trailed

Upvotes: 5

Views: 1325

Answers (7)

Dorad
Dorad

Reputation: 3713

Duplicating another well-aligned scene (View Controller) and deleting the corrupted one solved it.

Not sure what the problem was.

Upvotes: 0

harshal jadhav
harshal jadhav

Reputation: 5684

I tried a demo and i think what you need to do is set semantic for each label separately

go to perekSourcelabel set semantic right-to-left then do same for header label

dont set semantic for your stack view or the whole perekTableViewcell

Upvotes: 0

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16426

It is also depend on Your Device Selected Lang.

You can try to use left instead of leading and use right instead of trailing

Upvotes: 0

d.felber
d.felber

Reputation: 5408

If you use leading and trailing constraints to layout your UILabel elements, everything gets switched automagically to the right site if using a Right-To-Left language. There is no need to change the NSTextAlignment (.natural is default and the one you need) or the UISemanticContentAttribute of the UILabel. enter image description here


Be aware that you need to have at least one RTL language added to your project localizations:

enter image description here


When the language of your iPhone / iPad is set to Hebrew everything should work as expected:

enter image description here

Upvotes: 1

inspector_60
inspector_60

Reputation: 458

It seems that your constraints are wrong.

Constrain your labels to the right and align their text to the right.

Here is an example:

enter image description here

And running on simulator:

enter image description here

Upvotes: 1

Sakir Sherasiya
Sakir Sherasiya

Reputation: 1572

Just do following thing to assign text right side in tableviewCell

  • Step 1: Select view in contect View cell in StoryBoard

  • Step 2: Alignment text to right side.

Description image

Upvotes: 1

LGP
LGP

Reputation: 4323

Stack view configuration

For your stack view you should have alignment set to Leading to make it start at the leading position for your language, which is the right most side for you. Then you set Semantic to Force Right-to-Left.

It is important that you have tied the stack views edges to it's container's edges, so that the stack view will size to it's container. It is also important that you let the labels have dynamic size. Both of these conditions seems to be met in your code, although it is not entirely clear.

Upvotes: 1

Related Questions