开发者

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 a NSAttributedString, 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜