首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >带自定义下划线的NSAttributedString

带自定义下划线的NSAttributedString
EN

Stack Overflow用户
提问于 2019-03-19 22:21:20
回答 1查看 1.2K关注 0票数 3

有没有办法自定义NSAttributedString的下划线?我想要自定义:

文本与下划线宽度之间的下划线宽度和距离(underline color

  • Underline width

甚至可以在文本下创建自定义视图?

EN

回答 1

Stack Overflow用户

发布于 2019-03-19 23:02:53

我不认为这是一个完美的答案,只是半个证据。

我在这里添加了一些示例代码:

代码语言:javascript
复制
    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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55243195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档