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: 
I prefer `NSAttributedString` rather than `NSMutableAttributedString` for this simple case:

```
NSAttributedString * title =
    [[NSAttributedString alloc] initWithString:@"$198"
                                    attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
[label setAttributedText:title];

```

---

Constants for specifying both the `NSUnderlineStyleAttributeName` and `NSStrikethroughStyleAttributeName` attributes of an attributed string:

```
typedef enum : NSInteger {  
  NSUnderlineStyleNone = 0x00,  
  NSUnderlineStyleSingle = 0x01,  
  NSUnderlineStyleThick = 0x02,  
  NSUnderlineStyleDouble = 0x09,  
  NSUnderlinePatternSolid = 0x0000,  
  NSUnderlinePatternDot = 0x0100,  
  NSUnderlinePatternDash = 0x0200,  
  NSUnderlinePatternDashDot = 0x0300,  
  NSUnderlinePatternDashDotDot = 0x0400,  
  NSUnderlineByWord = 0x8000  
} NSUnderlineStyle;  

```
**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*