gpt4 book ai didi

ios - 如何使用 UILabel 或 UITextview 实现文本的 LineSpacing 和背景颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:33 24 4
gpt4 key购买 nike

enter image description here

如何制作一个 UILabel 或 UITextView 以在 swift 3 中实现这一点。

最佳答案

这里是带标签的解决方案。

let label = UILabel()
let stringValue = "How to implement LineSpacing and Background color of text with a UILabel"
let attrString = NSMutableAttributedString(string: stringValue)
var style = NSMutableParagraphStyle()
style.lineSpacing = 24 // change line spacing between paragraph like 36 or 48
style.minimumLineHeight = 20 // change line spacing between each line like 30 or 40
attrString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSRange(location: 0, length: stringValue.characters.count))

// background color
attrString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.red, range: NSRange(location: 0, length: stringValue.characters.count))

label.attributedText = attrString

关于ios - 如何使用 UILabel 或 UITextview 实现文本的 LineSpacing 和背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46541357/

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