iOS - copy all NSMutableAttributedString attributes to another NSMutableAttributedString -
i'd copy attributes 1 nsmutableattributedstring
new one. code i've tried this:
[attrstr enumerateattribute:nsfontattributename inrange:nsmakerange(0, attrstr.length) options:0 usingblock:^(id value, nsrange range, bool *stop) { if (value) { // uifont *oldfont = (uifont *)value; uifont *newfont = [_label.attributedtext [attrstr removeattribute:nsfontattributename range:range]; [attrstr addattribute:nsfontattributename value:newfont range:range]; //found = yes; } }];
the code incomplete , looks attempting fonts only. i'd loop through every attribute , add new nsmutableattributedstring
variable. update: question how apply attributes of 1 nsmutableattributedstring
nsmutableattributedstring
? can use method somehow:attribute:atindex:effectiverange
nsmutableattributedstring
(and nsattributedstring
) conforms nscopying
. should able this:
nsmutableattributedstring *mutablecopy = attrstr.mutablecopy; nsattributedstring *immutablecopy = attrstr.copy;
Comments
Post a Comment