1.如果只是靜態(tài)顯示textView的內(nèi)容為設(shè)置的行間距,執(zhí)行如下代碼:
//????textview 改變字體的行間距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 10;// 字體的行間距
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:15],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString alloc] initWithString:@"輸入你的內(nèi)容" attributes:attributes];
2.如果是想在輸入內(nèi)容的時候就按照設(shè)置的行間距進行動態(tài)改變,那就需要將上面代碼放到textView的delegate方法里
-(void)textViewDidChange:(UITextView *)textView
{
//? ? textview 改變字體的行間距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 20;// 字體的行間距
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:15],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
}