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

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

formula - R: how to pass in a reference to the variable in glm or lm? -