Skip to content

Instantly share code, notes, and snippets.

@MoussaHellal
Last active January 7, 2021 18:23
Show Gist options
  • Save MoussaHellal/63b8aec14bbda15a0e303ff8d7748edc to your computer and use it in GitHub Desktop.
Save MoussaHellal/63b8aec14bbda15a0e303ff8d7748edc to your computer and use it in GitHub Desktop.
extension String {
func strikeThrough() -> NSAttributedString {
let attributeString = NSMutableAttributedString(string: self)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0,attributeString.length))
return attributeString
}
}
// Usage
let hello = "Hello World".strikeThrough()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
label.attributedText = hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment