objective c - How change the font of attributed string in iOS? -


this question has answer here:

i have added attributed string on label.i displaying html text works fine default showing times new roman family. please tell how can change text family.

nsattributedstring *attributedstring = [[nsattributedstring alloc] initwithdata:[inst.desc datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; 

try this:

nsattributedstring *attributedstring = [[nsattributedstring alloc] initwithdata:[inst.desc datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; nsmutableattributedstring *newstring = [[nsmutableattributedstring alloc] initwithattributedstring:attributedstring]; nsrange range = (nsrange){0,[newstring length]}; [newstring enumerateattribute:nsfontattributename inrange:range options:nsattributedstringenumerationlongesteffectiverangenotrequired usingblock:^(id value, nsrange range, bool *stop) {     uifont *replacementfont =  [uifont fontwithname:@"palatino-roman" size:14.0];     [newstring addattribute:nsfontattributename value:replacementfont range:range]; }]; self.label.attributedtext = newstring; 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -