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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top