How to underline with NSAttributedString
This article will explain in detail how to underline with NSAttributedString. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
UILabel * lable = [[UILabel alloc] initWithFrame:CGRectMake (20,60,100,30)]
[self.view addSubview:lable]
Lable.backgroundColor = [UIColor redColor]
Lable.textAlignment = NSTextAlignmentCenter
NSString * oldPrice = @ "¥999999"
NSUInteger length = [oldPrice length]
[self.view addSubview:lable]
NSMutableAttributedString * attri = [[NSMutableAttributedString alloc] initWithString:oldPrice]
[attri addAttribute:NSStrikethroughStyleAttributeName value:@ (NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange (0, length)]
[attri addAttribute:NSStrikethroughColorAttributeName value: [UIColor yellowColor] range:NSMakeRange (0, length)]
[lable setAttributedText:attri]
This is the end of the article on "how to underline with NSAttributedString". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.