我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗?
在 San Francisco 字体中,如果括号围绕数字,则括号有点低.我正在制作的应用程序中的一个示例,使用 NSAttributedString
:
In the San Francisco font, brackets are a bit low if they surround numbers. An example from the app I'm making, using an NSAttributedString
:
我想将括号的基线增加一两个像素,但是当我使用 NSBaselineOffsetAttributeName
属性这样做时,行高也增加了两个像素.文本在 UITextView
内,我真的不希望行高改变.有什么我可以做的吗?
I'd like to increase the baseline for the brackets by a pixel or two, but when I do that using the NSBaselineOffsetAttributeName
attribute, the line height is increased by two pixels as well. The text is inside a UITextView
, and I really wouldn't like the line height to change. Is there anything I can do?
一种可能的方法是使用 NSParagraphAttributeName
强制最大行高.
A possible way to do it is to force the maximum line height with NSParagraphAttributeName
.
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setMaximumLineHeight:maxHeightWanted];
NSDictionary *parenthesisAttributes = @{NSParagraphStyleAttributeName:style,
NSBaselineOffsetAttributeName:@(baselineWanted),
NSFontAttributeName:sameFontWithBiggerPointSize};