9

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:.

Community
  • 1
  • 1
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213

2 Answers2

17

As of iOS 7 the NSBaselineOffsetAttributeName attribute has been added.

Luke Rogers
  • 2,369
  • 21
  • 28
Tommy
  • 99,986
  • 12
  • 185
  • 204
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.

Cocoanetics
  • 8,171
  • 2
  • 30
  • 57