设置UITextView的行间距有多种方法
一、设置静态textview行间距
UITextView不需要输入直接显示非常简单
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 100, 100, 200)];
textView.delegate = self;
textView.text = @"大家好大家好大家好大家好这是一个测试text";
[self.view addSubview:textView];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 5;// 字体的行间距
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:17],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
NSMutableParagraphStyle这个类,这是设置段落风格的类,有很多属性,请自行查看API
二、动态设置textview行间距
在textview的代理方法中实现动态改变行间距
- (void)textViewDidChange:(UIT