遇见的坑:1.选中状态失效,2.光标乱串
解决方法:
if(textView.markedTextRange == nil){
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 5;// 字体的行间距
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:14],
NSParagraphStyleAttributeName:paragraphStyle
};
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
NSRange oldRange = textView.selectedRange;
textView.attributedText = attributed;
textView.selectedRange = NSMakeRange(oldRange.location, 0);
}
网友评论