1

I've been having some problems centering text vertically beside an icon in a horizontal stack view. Here are some facts:

1) I create a view to hold stack view - add constraints

2) I place a horizontal stack view inside of that view - add width and height constraint, add vertically center constraint, add height constraint

3) Add an image and a label to the horizontal stack.

4) I make the image a certain width and match the height

5) I leave the label alone

6) I select the stack view and specify to set the Alignment to Center

In a new view controller this works great! Everything is perfectly aligned vertically. BUT in any existing controller I've created, it doesn't work! The text is rendered a few points above the center of the image, AND not at the top.

The only difference I can see is new view controller vs existing view controller, and simple layout compared to my more complex layout.

I have no auto layout errors, and don't really consider recreating all my view controllers to be an option. Anyone have any ideas?

James Scott
  • 990
  • 2
  • 10
  • 29
  • Please post your code. – Connor Neville Oct 19 '17 at 16:36
  • @Connor - thanks for the quick response! Unfortunately, this is not code related. Absolutely zero code... Also: I can't really post my project because company won't allow it. I can't post an example, because in my examples with new view controllers that I create it always works! So I'm in quite a pickle... – James Scott Oct 19 '17 at 16:38

1 Answers1

1

Wow, so I have this partially figured out. Its the custom font we are using for our app!

This was the primary difference. All my normal app views inherit from a base view where I set the font for the entire view. That is why when I tested in new view controllers (not inheriting from base) it would work.

If you are having trouble getting text perfectly vertically centered and you think you have done everything right, check your font.

Happy coding...

James Scott
  • 990
  • 2
  • 10
  • 29