Best way to strike out a text

天大地大妈咪最大 提交于 2019-12-20 01:47:19

问题


What is the best solution so far for a strike out text on the iPhone?

I heard of multiple solutions:

  • Something with three20
  • Image as a subview
  • UIWebView And something with a NSAttributedString, but I don't find a working example for that.

回答1:


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];



回答2:


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



来源:https://stackoverflow.com/questions/4017530/best-way-to-strike-out-a-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!