ios - Attributed string not showing bold and italic text with a specific font -


i receiving html string need display using uilabel. in case, don't add uifont see string expected.

+(nsattributedstring *)getattributedtext:(nsstring *)text { nsattributedstring *attrstr = [[nsattributedstring alloc] initwithdata:[text datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; return attrstr; } 

enter image description here

but font extremely small, need modify it.

+(nsattributedstring *)getattributedtext:(nsstring *)text { nsattributedstring *attrstr = [[nsattributedstring alloc] initwithdata:[text datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; nsmutableattributedstring *newstring = [[nsmutableattributedstring alloc] initwithattributedstring:attrstr]; nsrange range = (nsrange){0,[newstring length]}; [newstring addattribute:nsfontattributename value:[uifont fontwithname:@"opensans" size:14.0] range:range]; return newstring; } 

now, see text as

enter image description here

any other way of setting font while maintaining attributes?

+(nsattributedstring *)getattributedtext:(nsstring *)text {       text = [text stringbyappendingstring:[nsstring stringwithformat:@"<style>body{font-size:%fpx;}</style>", 15]];   // font size want display text        nsattributedstring *attrstr = [[nsattributedstring alloc] initwithdata:[text datausingencoding:nsunicodestringencoding]                                                                options:@{nsdocumenttypedocumentattribute: nshtmltextdocumenttype,                                                                          nscharacterencodingdocumentattribute: @(nsutf8stringencoding)}                                                     documentattributes:nil                                                                  error:nil]; } 

this may you...!!!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -