OGeek|极客世界-中国程序员成长平台

标题: ios - 我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:06
标题: ios - 我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗?

在 San Francisco 字体中,如果括号围绕数字,括号会有点低。我正在制作的应用程序的一个示例,使用 NSAttributedString:

example

我想将括号的基线增加一两个像素,但是当我使用 NSBaselineOffsetAttributeName 属性这样做时,行高也会增加两个像素。文本在 UITextView 内,我真的不希望改变行高。有什么我可以做的吗?



Best Answer-推荐答案


一种可能的方法是使用 NSParagraphAttributeName 强制设置最大行高。

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setMaximumLineHeight:maxHeightWanted];

NSDictionary *parenthesisAttributes = @{NSParagraphStyleAttributeName:style, 
                                        NSBaselineOffsetAttributeName(baselineWanted), 
                                        NSFontAttributeName:sameFontWithBiggerPointSize};

关于ios - 我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34727921/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4