Question: I want to create a `UILabel` in which the text is like this

![enter image description here](https://i.stack.imgur.com/pTq7k.png)

How can I do this? When the text is small, the line should also be small.

Answer: 
**SWIFT 4** 

```
    let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: "Your Text Goes Here")
    attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: NSMakeRange(0, attributeString.length))
    self.lbl_productPrice.attributedText = attributeString

```

Other method is to used String Extension  

**Extension**

```
extension String{
    func strikeThrough()->NSAttributedString{
        let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: self)
        attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: NSMakeRange(0, attributeString.length))
        return attributeString
    }
}

```

**Calling the function :** Used it like so

```
testUILabel.attributedText = "Your Text Goes Here!".strikeThrough()

```

**Credit to @Yahya** *- update Dec 2017*  

**Credit to @kuzdu** *- update Aug 2018*
**Swift 5**

```
extension String {

  /// Apply strike font on text
  func strikeThrough() -> NSAttributedString {
    let attributeString = NSMutableAttributedString(string: self)
    attributeString.addAttribute(
      NSAttributedString.Key.strikethroughStyle,
      value: 1,
      range: NSRange(location: 0, length: attributeString.length))

      return attributeString
     }
   }

```

Example:

```
someLabel.attributedText = someText.strikeThrough()

```