Is it possible to adjust the baseline in NSAttributedString?
Asked Answered
T

2

10

I'd like to slightly modify the y position of a character in an NSAttributedString. I know I can subscript (or superscript) using the attribute dictionary:

@{(id)kCTSuperscriptAttributeName: @(-1)}

Unfortunately the shift caused by this is too large in my case. I'm looking for an option to adjust the baseline in 1-point steps.

The attributed string will be displayed in a UIButton using -setAttributedTitle:forState:.

Treytri answered 11/1, 2013 at 15:34 Comment(0)
R
18

As of iOS 7 the NSBaselineOffsetAttributeName attribute has been added.

Rodina answered 24/6, 2014 at 0:0 Comment(0)
S
1

Yes you can... but only if you draw the text yourself like I am doing it in my DTCoreText open source project.

See line 924ff in DTCoreTextLayoutFrame.m here: https://github.com/Cocoanetics/DTCoreText/blob/master/Core/Source/DTCoreTextLayoutFrame.m

Unfortunately that's the ONLY way I know how to. UIKit does not give you this option.

Side answered 11/1, 2013 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.