【问题标题】:Create label background of dynamic strings in Swift在 Swift 中创建动态字符串的标签背景
【发布时间】:2016-07-03 16:37:26
【问题描述】:

如何设计这样的标签背景?

【问题讨论】:

标签: swift uikit


【解决方案1】:

您可以突出显示您的文字

导入 UIKit

let text = NSMutableAttributedString(string: "Hello")
text.addAttribute(NSBackgroundColorAttributeName, value: UIColor.grayColor(), range: NSMakeRange(0, text.length))
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 60, height: 100))
label.textColor = .whiteColor()    
label.attributedText = text

这是它的样子

【讨论】:

  • 我认为不是动态字符串
  • @NaqashKhalid:你什么意思?
  • 它只使用 1 个标签,但是当超过 1 个标签不起作用时,因为 x 和 y 发生了变化
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多