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 5 UPDATE CODE**

```
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "Your Text")
    attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSRange(location: 0, length: attributeString.length))

```

then:

```
yourLabel.attributedText = attributeString

```

**To make some part of string to strike then provide range**

```
let somePartStringRange = (yourStringHere as NSString).range(of: "Text")
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: somePartStringRange)

```

---

**Objective-C**

In **iOS 6.0 >** `UILabel` supports `NSAttributedString`

```
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
                        value:@2
                        range:NSMakeRange(0, [attributeString length])];

```

**Swift**

```
let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: "Your String here")
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))

```

**Definition** :

```
- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)aRange

```

`Parameters List:`

**name** : A string specifying the attribute name. Attribute keys can be supplied by another framework or can be custom ones you define. For information about where to find the system-supplied attribute keys, see the overview section in NSAttributedString Class Reference.

**value** : The attribute value associated with name.

**aRange** : The range of characters to which the specified attribute/value pair applies.

Then

```
yourLabel.attributedText = attributeString;

```

---

For `lesser than iOS 6.0 versions` you need `3-rd party component` to do this.
One of them is [TTTAttributedLabel](https://github.com/mattt/TTTAttributedLabel), another is [OHAttributedLabel](https://github.com/AliSoftware/OHAttributedLabel).
**Swift 4 and 5**

```
extension NSAttributedString {

    /// Returns a new instance of NSAttributedString with same contents and attributes with strike through added.
     /// - Parameter style: value for style you wish to assign to the text.
     /// - Returns: a new instance of NSAttributedString with given strike through.
     func withStrikeThrough(_ style: Int = 1) -> NSAttributedString {
         let attributedString = NSMutableAttributedString(attributedString: self)
         attributedString.addAttribute(.strikethroughStyle,
                                       value: style,
                                       range: NSRange(location: 0, length: string.count))
         return NSAttributedString(attributedString: attributedString)
     }
}

```

**Example**

```
let example = NSAttributedString(string: "440").withStrikeThrough(1)
myLabel.attributedText = example

```

**Results**

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