Uilabel working with HTML tags

Source: Internet
Author: User

Problem Description: 1. A large paragraph of text to be displayed, it is possible to have HTML tags, at this time if only the normal text text, the displayed page effect will be labeled text; 2. After the label is parsed, the displayed text is small, which makes it easy to make an error when changing the text size. Workaround: For example, the following code:nsstring *htmlstring = [_dictdata valueforkey:@ "introduce"]; Nsmutableattributedstring*attrstring = [[NsmutableattributedstringAlloc]Initwithdata: [htmlstringDatausingencoding:Nsunicodestringencoding]Options:@{Nsdocumenttypedocumentattribute:nshtmltextdocumenttype} documentattributes:nil error:nil]; [AttrstringAddAttribute:NsfontattributenameValue:[UifontSystemfontofsize:14] range:nsmakerange< Span style= "font:13.0px Menlo; Font-variant-ligatures:no-common-ligatures; " > (0, attrstring. length)];Webcell. lbdescription. Attributedtext = attrstring;  notes:1. Normal acquisition of text, using ordinary string;2. Change the string to a mutable property string, followed by a fixed notation;3. Change the text size so that the range is written as the number of variable attribute strings, because there are tags in the string, the label is converted into a variable attribute string, and the corresponding number is reduced by several times. 4. Put Uilabel first from the attribute text.

Uilabel working with HTML tags

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.