iOS loading HTML tags with lable and TextView

Source: Internet
Author: User

According to the application needs, the background will be sent over the HTML tag text displayed on the page, the first thought is to use wkwebview display, although it can be achieved but feel more memory consumption. Try loading HTML with lable, the code and the effect shown below, and find that the border style of the table is not loaded

NSString *str =@"Luomeng, Hello! Your borrowing item "0903. By month 3.02" the transfer of creditor's rights has been completed and the current holding information is as follows: <table border= ' 1 ' cellpadding= ' 0 ' width= ' 80%; ' cellspacing= ' 0 ' ><tr &GT;&LT;TD align= ' center ' > Username </td><td align= ' center ' > Debt holding amount </td></tr><tr><td align= ' center ' >13944831072</td><td align= ' center ' >2200.00</td></tr><tr><td align= ' center ' >13944831077</td><td align= ' center ' >600.00</td></tr><tr><td align= ' center ' >13944831078</td><td align= ' center ' >200.00</td></tr><tr><td align= ' center ' >13944831078</td><td align= ' center ' >200.00</td></tr><tr><td align= ' center ' >13944831078</td><td align= ' center ' >1800.00</td></tr><tr><td align= ' center ' >13944831078</td><td align= ' center ' >800.00</td></tr><tr><td align= ' center ' >13944831079</td><td align= ' center ' &GT;400.00&LT;/TD&GT;&LT;/TR&GT;&LT;/TABLE&GT "; UILabel*lab = [[UILabel alloc] Initwithframe:cgrectmake ( the, -, k_screen_widhth- -, -)];lab.numberoflines=0; [Self.view Addsubview:lab]; Nsattributedstring* Attrstr =[[Nsattributedstring alloc] initwithdata:[str datausingencoding:nsunicodestringencoding] options:@{ Nsdocumenttypedocumentattribute:nshtmltextdocumenttype} documentattributes:nil Error:nil];lab.attributedText =Attrstr;lab.font= [Uifont systemfontofsize: the];

And then hold on to the mentality of TextView loading HTML tags to find the border style can be displayed, it should be the bottom of the lab and TextView do different processing, code and the effect is as follows

Uitextview *textview = [[Uitextview alloc]initwithframe:cgrectmake (K_SCREEN_WIDHTH-30, 300)]; textview.userinteractionenabled = NO; [Self.view Addsubview:textview]; nsattributedstring * Attrstr = [[Nsattributedstring alloc] initwithdata:[str datausingencoding: Nsunicodestringencoding] options:@{Nsdocumenttypedocumentattribute:nshtmltextdocumenttype} documentAttributes: Nil Error:nil];textview.attributedtext = Attrstr;textview.font = [Uifont systemfontofsize:15];

Summary TextView and lable can load HTML tag content, but TextView can load the style of the tag at the same time compared to lable, of course, through the webview can also be implemented to the HTML load but relatively more memory is not recommended here, Hope to be helpful to friends who meet the same problem

iOS loads HTML tags with lable and textview

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.