我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗? [英] Can I adjust the baseline in an NSAttributedString without increasing the line height?

查看:41
本文介绍了我可以在不增加行高的情况下调整 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};

这篇关于我可以在不增加行高的情况下调整 NSAttributedString 中的基线吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆