目的:按區(qū)域(NSRange){a,x}設(shè)置文本背景顏色,a!=0 x為長度
現(xiàn)象:明明可以在iphone5顯示,iphone5s就是死活不顯示
分析了一下原因:
寫了個文本直接設(shè)置固定的位置與顏色,經(jīng)過測試,只要是{0,xxx}能顯示,{1,xxx}就是顯示不了,搞灰機,后來知道應該是ios版本升級后機制有修改,但不知道修改了啥!原來有人搞定了。
解決方法:
NSMutableAttributedString aString = [[NSMutableAttributedString alloc] initWithString:suport];
必須添加這句:
[aString addAttribute:(NSString)NSBackgroundColorAttributeName value:[UIColor clearColor] range:(NSRange){0,aString.length}];//必須將原來所有文字的背景置為clearcolor
[aString addAttribute:(NSString*)NSBackgroundColorAttributeName value:[UIColor redColor] range:(NSRange){1,aString.length-2}];//然后再添加屬性顏色就可以了