我使用NSAttributedString
(和NSMutableAttributeString
)通过UIGraphicsBeginPDFContextToFile
编写PDF。当我输出带有下划线属性的属性字符串时,下划线会在下划线上的字母下降处断开。
下面是一个显示当前输出的示例(屏幕截图):
下面是构建该示例属性字符串的代码:
NSAttributedString* ftype =
[[NSMutableAttributedString alloc]
initWithString:@"Dangerous"
attributes:@{
NSParagraphStyleAttributeName:pstyle,
NSFontAttributeName:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:48.0],
NSForegroundColorAttributeName:[UIColor redColor],
NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]
}
];
我的客户和我的偏好是,下划线应该是连续的,最好是移到下划线下面。
手工绘制下划线是很困难的,因为我们必须在布局后计算单词的文本位置(有时文本并不像上面的例子那样简单)。
有没有人用固定的方法把下划线放低一点,或者( b)让下划线连续?
提前谢谢。
发布于 2014-09-05 19:05:22
我知道这是旧的,在搜索之后找不到答案。我找到的解决方案是在您传递给NSAttributedString initWithString: attributes : add以下属性的字典中
NSExpansionAttributeName:@-0.0001f
这是刻度的字形,它似乎即使在这么小的数量,下划线没有被削减(嗯,它没有与我使用的13pt字体)。虽然这看起来不像是NSExpansionAttributeName的预期用途,但却找不到另一个解决方案。
https://stackoverflow.com/questions/17697881
复制相似问题