Best way to strike out a text
What is the best solution so far for a strike out text on the iPhone?
I heard of multiple soluti开发者_运维问答ons:
- Something with three20
- Image as a subview
UIWebView
And something with aNSAttributedString
, but I don't find a working example for that.
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];
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
精彩评论