IOS UILabel: html Tag, iosuilabel

Source: Internet
Author: User

IOS UILabel: html Tag, iosuilabel

After iOS7, the system provides the html Tag display method.

UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE_IOS (7_0 );

Directly Add code

NSString * str = @ "<font color = \" # 6c6c6c \ "> full 20 minus 5 minus 40 minus 15, <font color = \ "# ff9147 \"> 113 days left "; UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (30, 50,300, 50)]; NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData: [str dataUsingEncoding: encoding] options :@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes: nil error: nil. attributedText = attrStr; // if you want to change the text font, set the label after attributedText. font = [UIFont systemFontOfSize: 20]; [self. view addSubview: label];

Code Effect

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.