IOS development skills – add text to the text through the horizontal line

In iOS development, we might want this effect, especially on commodity prices:

IOS development skills - add text to the text through the horizontal line
Snip20160513_8.png

So here comes the question, how does this effect come true? Don’t talk nonsense, go to the code!!

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake (20, 50, 200, 50)]; [self.view addSubview:label]; label.text = @ "12.89"; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor grayColor]; / / line color with label font color change NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@ ", label.text]] [newPrice $% @" (value:@; addAttribute:NSStrikethroughStyleAttributeName NSUnderlinePatternSolid NSUnderlineStyleSingle |) range:NSMakeRange (0, newPrice.length); label.attributedText = newPrice;

Here uses the
– (void) addAttribute: (NSString *), name, value: (ID), value, range: (NSRange), range;
, the attribute plus a horizontal line.

OK, the effect is the one in front.