6 Replies
      Latest reply on Mar 7, 2019 9:47 AM by OCA92
      OCA92 Level 1 Level 1 (0 points)

        I have three UILabels embedded in a horizontal Stack which is in a Content view of a UITable (eg. the labels will display in the row). Settings for the three UILabels are the same : Font System 17, Lines 1, Baseline None. No constraints

        The text of each UILabel is expected to be vertically centered in the row but is not. The text is actually aligned to the top of the row, like if there were two lines to display in the row.

        I tried to add constraints (align in container), or change Baseline, or set the Height with no effect.

        Any idea or suggestion ?

         

        Illustration of a row : the accessory image is nicely vertically centered but not the text

        -------------------------

        text

                                         >

         

        ------------------------

        • Re: Text in UILabel doesn't center vertically
          Claude31 Level 8 Level 8 (5,775 points)

          Did you add constraints for the stackview ?

           

          That is what I would try: center stackView vertically in cell.

            • Re: Text in UILabel doesn't center vertically
              OCA92 Level 1 Level 1 (0 points)

              Thanks Claude, and sorry for the late answer.

              I did try to put constraints. With no effects.

              Currently, I have for the Stack : Center X, Center Y, Height = 22 ; no contraints for the 3 Labels

                • Re: Text in UILabel doesn't center vertically
                  Claude31 Level 8 Level 8 (5,775 points)

                  I have tested the setup with an horizontal stackView in the ContentView of the cellPrototype of a UITable.

                   

                  The stack is normally displayed at the top.

                  So, I selected stackView and, in Size Inspector, I set Arrange -> positionView to center vertically.

                  Now the stack is drawn in a lower position.

                   

                  I also tried to set constraint for the label relative to stackView, but there is a default constraint to align top of label to stackView which is conflicting.

                    • Re: Text in UILabel doesn't center vertically
                      OCA92 Level 1 Level 1 (0 points)

                      When the stack displays normally, it should be centered vertically and not at the top.

                      I set the Arrange PositionView Center vertically in container but no effect

                      I then deleted the three Labels and recreated them, no effect

                       

                      The Accessory, on the right end side is well centered vertically, but not the three Labels, still

                        • Re: Text in UILabel doesn't center vertically
                          Claude31 Level 8 Level 8 (5,775 points)

                          A solution would probably to get rid of the stack, to get more control.

                           

                          Before that, if you want to post an email where to contact, so that you can send code in return for testing.

                            • Re: Text in UILabel doesn't center vertically
                              OCA92 Level 1 Level 1 (0 points)

                              I got rid of the Stack. Labels were correctly vertically aligned. However, they were not large enough and superimposed on each other. I added Width and Constraints. Got the mess again with wrong alignment. I removed the constraints it came back correctly. After many attempts, add, remove, change, same mess. But finally, by just setting the Width for each and without any other constraints, it works fine. It's unclear to me how width or horizontal alignment can impact vertical alignment. This is very unpredictable. In addition, my second screen, still with a Stack and three Labels work fine from the beginning. I will commit the current setup. Thanks again for the tip.