Reputation: 54121
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:
.
Upvotes: 10
Views: 6572
Reputation: 100632
As of iOS 7 the NSBaselineOffsetAttributeName
attribute has been added.
Upvotes: 18
Reputation: 8247
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.
Upvotes: 1