Friday, 23 August 2013

Updated substring in NSAttributedString

Updated substring in NSAttributedString

How I can replace substring in NSMutableAttributedString without adding
static range number? I have a label with this text: @"12 friends", I want
to replace 12 (number of friends) with another number once that it will
come from the server, and I can not use the below approach since the
number of digits is unknown:
/*wrong approach*/
NSMutableAttributedString *mutableAttributedString =
[[NSMutableAttributedString alloc]
initWithAttributedString:label.attributedText];
[mutableAttributedString replaceCharactersInRange:NSMakeRange(0, 2)
withString:counter];
[label setAttributedText:mutableAttributedString];

No comments:

Post a Comment