3

What is the best solution so far for a strike out text on the iPhone?

I heard of multiple solutions:

  • Something with three20
  • Image as a subview
  • UIWebView And something with a NSAttributedString, but I don't find a working example for that.
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
gabac
  • 2,062
  • 6
  • 21
  • 30

2 Answers2

10

In iOS 6 we can use "NSMutableAttributedString" for use more different styles.

    NSString* cutText = @"This Line is strike out.";

    NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:cutText];

    // making text property to strike text- NSStrikethroughStyleAttributeName
    [titleString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [titleString length])];

    // using text on label
    [myTextLabel  setAttributedText:titleString];
HDdeveloper
  • 4,396
  • 6
  • 40
  • 65
-1

You can try my solution of UILabel subclass, which supports:

multiline text with various label bounds (text can be in the middle of label frame, or accurate size)

  • underline
  • strikeout
  • underline/strikeout line offset
  • text alignment
  • different font sizes

https://github.com/GuntisTreulands/UnderLineLabel

Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72