NSMutableRLEArray objectAtIndex:effectiveRange ::越界 [英] NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds

查看:272
本文介绍了NSMutableRLEArray objectAtIndex:effectiveRange ::越界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将属性分配给 newClock 字符串的3个最后字符,即 @3:33:23

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

但是当构造 NSRange 时出现错误:

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)];


推荐答案

NSMakeRange(i,j)创建一个包含位置的范围i和长度j。

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

例如,如果您的字符串大小为10且范围从5开始,则执行此操作:

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

NSMakeRange(5,10)

你的范围从5到15,所以超出你的字符串。

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

尝试:

NSMakeRange(newClock.length-3,3)];

这篇关于NSMutableRLEArray objectAtIndex:effectiveRange ::越界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆