Last active
January 7, 2021 18:23
-
-
Save MoussaHellal/63b8aec14bbda15a0e303ff8d7748edc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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