저는 UITextView가 있는데이 텍스트의 특정 부분을 선택하고 스타일을 수정하고 싶습니다. 색상 변경, 기울임 꼴 또는 굵게, 글꼴 크기를 늘리거나 글꼴 군을 변경하는 것과 같습니다.UITextView - 선택한 텍스트 수정
어떤 도움말이 필요합니까?
저는 UITextView가 있는데이 텍스트의 특정 부분을 선택하고 스타일을 수정하고 싶습니다. 색상 변경, 기울임 꼴 또는 굵게, 글꼴 크기를 늘리거나 글꼴 군을 변경하는 것과 같습니다.UITextView - 선택한 텍스트 수정
어떤 도움말이 필요합니까?
예. iOS 5를 기다려주세요. iOS 5에 대한 대부분의 정보가 아직 NDA에 있다고 생각합니다. 따라서 여기서 논의 할 수는 없습니다.
또는 CoreText로 직접 개발하십시오. 다음과 같이
당신은 몇 가지 다른 일을 사용할 수 있습니다 : -
shouldChangeTextInRange
을 사용해야합니다. 이는 텍스트를 변경하려는 위치를 찾기 위해 범위가 필요하기 때문입니다.
UITextView를 사용하면 textView.attributedString
에 스타일을 저장할 수 있습니다.
해결책은 textView의 Attributed String을 가져 와서 원하는 하위 문자열을 변경되거나 스타일이 적용된 텍스트로 바꾸는 것입니다.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
NSMutableAttributedString *textViewText = [[NSMutableAttributedString alloc]initWithAttributedString:textView.attributedText]; //gets textView style string
NSRange selectedTextRange = [textView selectedRange];
NSString *selectedString = [textView textInRange:textView.selectedTextRange]; //our selected text
//lets say you always want to make selected text bold
UIFont *boldFont = [UIFont boldSystemFontOfSize:self.txtNote.font.pointSize];
NSDictionary *boldAttr = [NSDictionary dictionaryWithObject:boldFont forKey:NSFontAttributeName];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]initWithString:selectedString attributes:boldAttr]; //make attributed string of our selectedtext
[textViewText replaceCharactersInRange:range withAttributedString:attributedText]; // replace
textView.attributedText = textViewText;
return false;
}
약간 중복됩니다. http://stackoverflow.com/questions/3841108/uitextfield-make-text-bold – Legolas
전체 텍스트가 아니라 전체 텍스트를 굵게 표시해야합니다. thnx –