美文网首页
textView设置行间距方法

textView设置行间距方法

作者: lvzhehappy | 来源:发表于2017-04-10 15:16 被阅读15次

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

}

相关文章

网友评论

      本文标题:textView设置行间距方法

      本文链接:https://www.haomeiwen.com/subject/hcpsattx.html