1

How can I write a string like the following:

H̶̶o̶̶w̶ ̶t̶̶o̶ ̶w̶̶r̶̶i̶̶t̶̶e̶ ̶t̶̶h̶̶i̶̶s̶ ̶t̶̶e̶̶x̶̶t̶

In my app, I need to display the past price of a product that has been replaced by a new price. Like so:

$̶8̶̶0̶̶0̶ -> $600

jscs
  • 63,694
  • 13
  • 151
  • 195
Jonny Vu
  • 1,420
  • 2
  • 13
  • 32
  • 3
    Look for `NSAttributedString` & `NSStrikethroughStyleAttributeName` – Larme Apr 19 '14 at 16:38
  • @Larme Could you tell me more for this, or could you tell me the name for this kind of character. It would be good for me search more. Tks – Jonny Vu Apr 19 '14 at 16:41
  • 1
    @VũTuấnAnh There are strikethrough characters in UTF8. You can use those directly in an Obj-C string. E.g. `@"8̶0̶0̶"`. See http://en.wikipedia.org/wiki/Strikethrough#Unicode – mostruash Apr 19 '14 at 16:46

1 Answers1

4

To get this result you should use NSAttributedString and set the attribute name NSStrikethroughStyleAttributeName. The number used as object for this key defines the style of the line over the text.

self.myLabel.attributedText = [[NSAttributedString alloc] initWithString:@"800" attributes:@{NSStrikethroughStyleAttributeName: @1}];

Cheers

Eduardo Lino
  • 791
  • 7
  • 9
  • It seem to easy but my English is not good. This kind of character is "Strikethrough". Tks for your help – Jonny Vu Apr 19 '14 at 16:55