최근에 NSAtributedString이 어떻게 작동하는지 조사하기 시작했습니다. NSAtributedString을 사용하여 서식있는 텍스트 편집기와 비슷한 것을 구축하고 있습니다. 나는 정의 작성 CustomRichTextEditor 있습니다 UITextView 난 다음이 코드를 사용 NSAtributedString에 대한 기본 속성을 덮어 쓰려면 :NSAtributedString 색상 및 빈 범위에 대한 글꼴 변경 TextView
: 내 편집기가 비어와 범위를 알 수 없기 때문에
UIFont *font = [UIFont systemFontOfSize:24.0];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,[UIColor darkGrayColor],NSForegroundColorAttributeName,nil];
NSMutableAttributedString* attrStr = [self.richTextEditor.attributedText mutableCopy];
[attrStr setAttributes:attributes
range:NSMakeRange(0, self.richTextEditor.attributedText.string.length-1)
];
self.richTextEditor.attributedText = attrStr;
그러나, 나는 오류로 충돌 인해 캐치되지 않는 예외 'NSRangeException'응용 프로그램 종료, 이유는 : 'NSMutableRLEArray replaceObjectsInRange : withObject : 길이 ::의 아웃 바운드'
범위를 알 수없는 올바르게 때 나는 NSAtributedString의 글꼴과 색상을 설정할 수있는 방법?
self.richTextEditor.attributedText.string.length-1
오류를 만들 수 있습니다
왜 self.richTextEditor.attributedText.string.length? 마지막 캐릭터를 자르고 있습니다. –
그건 사실이야! – Georg
문제는 분명하지만 범위를 지정하지 않으면 어떻게 해결할 수 있습니까? – Vad