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

标签 iphone ios nsattributedstring

我正在使用 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/

相关文章:

Xcode 中的 iOS 应用程序内存使用量不断上升

iphone - 如何轻松地将分贝读数的值传递到动态针图形

iOS 的 Tableview 单元格上的半透明 View 渗透到其他单元格上

ios - requestFinished 方法内的 ASIFormDataRequest

ios - 文本渲染 iOS - 渲染快速变化的文本的最高效方式

ios - SKStoreProductViewController 显示来自开发者的应用程序

ios - iPhone 6 Plus 支持字体问题

iphone - 核心数据实体中配置错误的属性

ios - NSTextAttachment 以某种方式缓存图像。关于如何做有什么想法吗?

ios - swift 3 使用 NSAttributedString 加载 HTML 数据时设置字体失败?