gpt4 book ai didi

iphone - 寻找 : iOS 6 NSAttributedString Descenders Block Underline 的解决方法

转载 作者:可可西里 更新时间:2023-11-01 04:44:16 25 4
gpt4 key购买 nike

我正在使用 NSAttributedString(和 NSMutableAttributeString)通过 UIGraphicsBeginPDFContextToFile 写入 PDF。当我输出带有下划线属性的属性字符串时,下划线会在字母下行部分超过下划线时断开。

这是显示当前输出的示例(屏幕截图):

sample underline image

下面是构建示例属性字符串的代码:

NSAttributedString* ftype = 
[[NSMutableAttributedString alloc]
initWithString:@"Dangerous"
attributes:@{
NSParagraphStyleAttributeName:pstyle,
NSFontAttributeName:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:48.0],
NSForegroundColorAttributeName:[UIColor redColor],
NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]
}
];

我的客户和我的偏好是下划线是连续的,并且最好移动到下行线下方。

手动绘制下划线很困难,因为我们必须在布局后计算单词的文本位置(有时文本不像上面的示例那么简单)

有没有人有办法把下划线放在 a) 较低或 b) 使其连续?

提前致谢。

最佳答案

我知道这是旧的,搜索后没有找到答案。我找到的解决方案是在您将属性传递给 NSAttributedString 的字典中 initWithString:attributes: 添加这个

NSExpansionAttributeName : @-0.0001f

这会缩放字形,看起来即使是这么小的量,下划线也不会被剪掉(好吧,我使用的 13pt 字体没有剪掉)。虽然这看起来不像是 NSExpansionAttributeName 的预期用途,但找不到其他解决方案。

关于iphone - 寻找 : iOS 6 NSAttributedString Descenders Block Underline 的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17697881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com