NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds
Asked Answered
P

1

18

I try to assign attributes to 3 last chars of newClock string, which is @"3:33:23".

However I get an error when construct NSRange:

NSMutableAttributedString *mas = [[NSMutableAttributedString alloc]initWithString:newClock];
[mas addAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]}
 range:NSMakeRange(newClock.length-3,newClock.length)];
Phox answered 13/10, 2013 at 11:28 Comment(0)
B
44

NSMakeRange(i, j) creates a range with location i and length j.

If for example the size of your string is 10 and your range starts in 5, and you do this:

NSMakeRange(5,10)

Your range goes from 5 to 15, so out of your string.

Try:

NSMakeRange(newClock.length-3,3)];
Budgie answered 13/10, 2013 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.