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; }
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
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
Post a Comment