UILabel Strikethrough

前端 未结 5 1852
孤城傲影
孤城傲影 2020-12-30 07:26

Is it possible to stikethrough a UILabel at all? I can\'t seem to find the option...

相关标签:
5条回答
  • 2020-12-30 07:43

    You could create another UILabel above your label and use an en dash character:

    label.text = @"––––––––––––––––––";
    

    Caveat: works with Helvetica (system default). It may not work with other fonts.

    0 讨论(0)
  • 2020-12-30 07:47

    This is an old question and newer information is available.

    Starting in iOS 6, we have NSAttributedString.

    For pre iOS 6, I would look at TTTAttributedLabel

    0 讨论(0)
  • 2020-12-30 07:51

    iPhone doesn't support attributed strings (which is usually the way you'd do this in Cocoa), so I don't believe it's possible.

    You could subclass UILabel and draw the strikethrough yourself. I've also seen some people use a UIWebView to do this type of thing, but that seems like overkill to me.

    0 讨论(0)
  • 2020-12-30 07:54
    NSAttributedString *str=[[NSMutableAttributedString alloc]  initWithString:[NSString stringWithFormat:@"¥%.2f", productOne.priceBefore]  attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
    
    cell.priceBefore.attributedText = str;
    
    0 讨论(0)
  • 2020-12-30 07:55
    UIView* slabel = [[UIView alloc] initWithFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y+10, label.frame.size.width, 2)];
    [self addSubview:slabel];
    [slabel setBackgroundColor:label.textColor];
    

    You can add a view over UILabel and style it with label properties.

    0 讨论(0)
提交回复
热议问题