Can I set up a baseline in an NSAttributedString?

I want to slightly change the y-position of the character in NSAttributedString . I know that subscript (or superscript) can be used with an attribute dictionary:

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

Unfortunately, the shift caused by this is too big in my case. I am looking for the opportunity to adjust the basic level in increments of 1 point.

The assigned string will be displayed in UIButton with -setAttributedTitle:forState:

+7
source share
2 answers

Starting with iOS 7, the NSBaselineOffsetAttributeName attribute has been added.

+12
source

Yes, you can ... but only if you draw the text yourself, as I do in my open source DTCoreText project.

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

Unfortunately, ONLY I know how to do this. UIKit does not give you this opportunity.

+1
source

All Articles