ios - swift 的 iOS。多行 UILabel 背景颜色跟随文本

标签 ios swift uilabel background-color

我有一个多行 UILabel,我想将其背景颜色设置为与您用鼠标在网络浏览器上突出显示文本时完全相同,但似乎找不到解决方案。

这是我在 Storyboard中得到的: enter image description here

这就是我的目标:

enter image description here

这是我上面提到的浏览器示例: enter image description here

最佳答案

是的,使用属性文本。此处为 swift

let textBgColor = UIColor.greenColor()
let attributes = [
        NSBackgroundColorAttributeName : textBgColor
]
let attributedString = NSAttributedString(string: Constant.kDescriptionArray[0], attributes: attributes)

descriptionLabel.attributedText = attributedString

关于ios - swift 的 iOS。多行 UILabel 背景颜色跟随文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38068228/

相关文章:

ios - 防止登录 Swift/Parse 中的 Segue 转换

ios - UICollectionView 单元测试 dequeueReusableCellWithReuseIdentifier 上的错误访问

ios - 容器 View Controller 应用程序在 Swift 中崩溃 NSInternalInconsistencyException?

ios - swift 4 - 在segue动画完成后如何在目标 View Controller 中运行代码?

ios - OpenGL ES "imperfection"

iphone - 裁剪后的 UIButton 标题

ios - 动态对比文本颜色

ios - 如何删除一行 UILabel 下方的额外填充

ios - MPmovieplayer 和流式 m3u8 文件?

ios - 从 ios 库中的视频获取持续时间和创建日期