遇見(jiàn)的坑:1.選中狀態(tài)失效,2.光標(biāo)亂串
?解決方法:
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);
}