有没有办法自定义NSAttributedString的下划线?我想要自定义:
文本与下划线宽度之间的下划线宽度和距离(underline color
甚至可以在文本下创建自定义视图?
发布于 2019-03-19 23:02:53
我不认为这是一个完美的答案,只是半个证据。
我在这里添加了一些示例代码:
let text = NSMutableAttributedString.init(string: "hello")
let range = NSMakeRange(0, text.length)
// add large fonts
text.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.red, range: range)
text.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.blue, range: range)
text.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 72), range: range)
// add underline
text.addAttribute(NSAttributedString.Key.underlineStyle, value: NSNumber(value: NSUnderlineStyle.double.rawValue), range: range)
text.addAttribute(NSAttributedString.Key.underlineColor, value: UIColor.green, range: range)
textView.attributedText = text
https://stackoverflow.com/questions/55243195
复制相似问题