Swift设置textView的行间距
let textview = UITextView(frame: CGRect(x: 100, y: 100, width: 100, height: 200))
let paraph = NSMutableParagraphStyle()
paraph.lineSpacing = 10;// 字体的行间距
let attributes = [NSFontAttributeName:UIFont.systemFont(ofSize: 15),NSParagraphStyleAttributeName: paraph]
textview.attributedText = NSAttributedString(string: "你的文字", attributes: attributes)
//如果是想在输入内容的时候就按照设置的行间距进行动态改变,那就需要将上面代码放到textView的delegate方法里
func textViewDidChange(_ textView: UITextView) {
let paraph = NSMutableParagraphStyle()
paraph.lineSpacing = 10;// 字体的行间距
let attributes = [NSFontAttributeName:UIFont.systemFont(ofSize: 15),NSParagraphStyleAttributeName: paraph]
textView.attributedText = NSAttributedString(string: "你的文字", attributes: attributes)
}