textView设置行间距方法

2017-04-10  本文已影响15人  lvzhehappy

遇见的坑: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);

}

上一篇 下一篇

猜你喜欢

热点阅读