Get the App
SLTechnology News&Howtos  ›  Development  › 

How to underline with NSAttributedString

Shulou Source: shulou.com Published: 2022-06-02 12:15:12 10月04日 Update

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.

Tags: Articles underlines more good practical content articles knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info macOS Xiaomi OPPO Reno