5

I have a NSAttributedString which is a "table" using NSTextTab stops where the first column is the KEY and the second column is the value

Like this:

|  **KEY 1**|value1|
|**KEY TWO**|value2|

The font for the KEYS is different size/weight + it is all caps. The rows align so that the bottoms of all the letters match up. I would like to nudge the values up vertically so that they appear to be vertically centered with the KEYS.

Is there any way to do this? This seems highly specialized, but from a design perspective I think it will look much better

tettoffensive
  • 664
  • 7
  • 24
  • You mean horizontally center if you want to align the bottom line. – qwerty_so May 22 '15 at 21:21
  • @ThomasKilian No, vertically centered is correct. As I understand the question, the OP wants the Y-values of the centers of the key and its corresponding value to match. – Caleb May 22 '15 at 21:28
  • @Caleb Yes. This is called a horizontal alignment. Where on a horizontal line you dock element on an imaginary line. – qwerty_so May 22 '15 at 22:20
  • While I understand how you could interpret it both ways as it's an imaginary horizontal line, I believe that vertical alignment generally refers to lining up in the Y direction. – tettoffensive May 23 '15 at 21:12

1 Answers1

10

I haven't tried it, but it seems like you should be able to use NSBaselineOffsetAttributeName for this. Here's what the docs say about it:

The value of this attribute is an NSNumber object containing a floating point value indicating the character’s offset from the baseline, in points. The default value is 0.

So you'll probably have to compute the number of points needed to move the values up -- I guess that'd be half the difference in font sizes between the keys and values. Then apply NSBaselineOffsetAttributeName with that number of points to the text for the values.

Caleb
  • 124,013
  • 19
  • 183
  • 272