Change character spacing on UILabel within Interface Builder

前端 未结 13 2559
说谎
说谎 2020-12-23 09:21

Is there anyway to change the character spacing (track) on UILabel text using Interface Builder? If not, is there a way to do it programmatically on an existing UILabel that

相关标签:
13条回答
  • 2020-12-23 09:56

    Swift 5 and higher

    extension UILabel {
      func setTextSpacingBy(value: Double) {
        if let textString = self.text {
          let attributedString = NSMutableAttributedString(string: textString)
          attributedString.addAttribute(NSKernAttributeName, value: value, range: NSRange(location: 0, length: attributedString.length - 1))
          attributedText = attributedString
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题