Search code examples
iosswiftxcodeuilabelstrikethrough

Swift: strikethroughStyle For Label (Middle Delete Line For Label)


How to add strikethroughStyle for label. A middle delete line to a number in UILabel. Check the attach image for reference.

enter image description here


Solution

  • Use attributeString

    Screenshot

    enter image description here

    Code

    NSDictionary * attribtues = @{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),
                                  NSStrikethroughColorAttributeName:[UIColor redColor]};
    NSAttributedString * attr = [[NSAttributedString alloc] initWithString:@"label" attributes:attribtues];
    self.label.attributedText = attr;