8

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
  • 50,501
  • 24
  • 131
  • 209

2 Answers2

16

As of iOS 7 the NSBaselineOffsetAttributeName attribute has been added.

Luke Rogers
  • 2,289
  • 20
  • 26
Tommy
  • 98,579
  • 12
  • 179
  • 201
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,061
  • 2
  • 26
  • 54