iPhone - Strike out an NSString [duplicate]

2019-06-05 02:27发布

问题:

This question already has an answer here:

  • Best way to strike out a text 2 answers

I would like to know if there is an easy way to strike/cross out some text on the iPhone?

Thanks

回答1:

Yes and No,

NSString is a simple class, that only stores unformated text, but you can use an NSAttributedString to store such information, i.e.

NSAttributedString* italicText = [[NSAttributedString alloc] initWithString:myNsString attributes:myCrossOutAttributes];


回答2:

NSMutableAttributedString *strikeThroughString = [[NSMutableAttributedString alloc] initWithString:anyString];
[strikeThroughString addAttribute:NSStrikethroughStyleAttributeName value:(NSNumber *)kCFBooleanTrue range:NSMakeRange(0, [as length])];
[m_cObjTaskTitle setAttributedText:strikeThroughString =];
cObjTaskTitle = UILabel ;