Skip to content

Instantly share code, notes, and snippets.

@nitin-agam
Last active January 22, 2025 02:34
Show Gist options
  • Save nitin-agam/3ec783853797fe06dbea369f3a7c347e to your computer and use it in GitHub Desktop.
Save nitin-agam/3ec783853797fe06dbea369f3a7c347e to your computer and use it in GitHub Desktop.
extension UILabel {
static func spaceLabel() -> UILabel {
let spacingLabel = UILabel()
spacingLabel.frame = CGRect(x: 0, y: 0, width: 150, height: 50)
spacingLabel.textColor = .white
spacingLabel.textAlignment = .center
spacingLabel.font = UIFont.boldSystemFont(ofSize: 18)
spacingLabel.text = "LIKE ME"
spacingLabel.backgroundColor = .red
return spacingLabel
}
// adding space between each characters
func addCharacterSpacing(kernValue: Double = 3) {
if let labelText = text, labelText.isEmpty == false {
let attributedString = NSMutableAttributedString(string: labelText)
attributedString.addAttribute(.kern,
value: kernValue,
range: NSRange(location: 0, length: attributedString.length - 1))
attributedText = attributedString
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment