我试图创建一个属性串,但下划线涵盖了我的文字,而不是显示它背后的:下划线涵盖文字NSAttributedString
是有办法解决这一问题?我正在使用以下代码:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10.0
let attributes = [NSForegroundColorAttributeName: UIColor.white,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleThick.rawValue,
NSUnderlineColorAttributeName: UIColor.red,
NSParagraphStyleAttributeName: paragraphStyle]
let attributedString = NSAttributedString(string: "Story", attributes: attributes)
谢谢!
编辑:
为了让更多的上下文:
我上显示一个UILabel的属性串放在一个文件的.xib:
view.textLabel.attributedText = attributedString
标签有以下字体: 系统粗体32.0
我在iPhone 6 - iOS 10.3模拟器上运行代码。
编辑2:
我应该提到的是,标签可能在某些时候,包含文本的多行。这就是为什么numberOfLines设置为0.
编辑3: 如果有人遇到这个问题 - 好像在iOS 9和10以及UILabel和UITextView上绘制下划线有很大的区别。我最终不得不通过继承NSLayoutManager来自己绘制下划线。
无法重现问题。在我的机器上,下划线很好地与文本分开,并且不与“y”的下行相交。 https://i.stack.imgur.com/uXs4R.png请显示更多的代码,使其具有可重现性。你如何显示这个属性字符串?你使用什么字体?等等。 – matt
同样在这里,我也无法在我的机器上复制您的问题。它与文本很好地分开显示。 @GrzegorzAperliński – iPeter
(另外我可能会提到你的代码没有在我的机器上编译,需要明确声明'attributes'属于类型'[String:Any]'。) – matt