How can I vertically center a string in an NSAttributedString with different fonts?
I have NSAttributedString
which is a "table" using NSTextTab
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 KEYS is a different size / weight + all caps. The lines are aligned so that the bottoms of all letters match. I would like to nudge the values ββvertically so that they appear vertically centered using KEYS.
Is there a way to do this? This seems highly specialized, but in terms of design I think it will look much better
source to share
I haven't tried it, but it looks like you should be using 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 that indicates the off-baseline characters in points. Default value: 0.
So you probably have to figure out the number of dots needed to move the values ββ- I think that would be half the difference in font sizes between keys and values. Then apply NSBaselineOffsetAttributeName
with as many dots to the text for the values.
source to share