Sometimes we need to add a horizontal line to the text, in two ways:
The first is the horizontal line running through the middle:
The color of the horizontal line is consistent with the color of the text
_oldpricelabel.text = @ "3500";
_oldpricelabel.textcolor = [Uicolor lightgraycolor];
nsmutableattributedstring *newprice = [[Nsmutableattributedstring alloc] initwithstring:[nsstring stringWithFormat:@ "¥%@", _oldpricelabel.text]];
[Newprice addattribute:nsstrikethroughstyleattributename value:@ (nsunderlinepatternsolid | Nsunderlinestylesingle) range:nsmakerange (0, Newprice.length)];
_oldpricelabel.attributedtext = Newprice;
Effect as shown:
The second way is to underline text:
The code is as follows:
nsmutableattributedstring *title = [[Nsmutableattributedstring alloc] initwithstring:@ "Forget password. "];
Nsrange Titlerange = {0,[title length]};
[title Addattribute:nsunderlinestyleattributename Value:[nsnumber Numberwithinteger:nsunderlinestylesingle] Range: Titlerange];
[_forgetbtn setattributedtitle:title
Forstate:uicontrolstatenormal];
The effect of the following figure: