设置textView的行间距
来源:互联网 发布:御剑青云传进阶数据 编辑:程序博客网 时间:2024/05/17 02:56
1.如果只是静态显示textView的内容为设置的行间距,执行如下代码:
// textview 改变字体的行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 10;// 字体的行间距
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:15],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString alloc] initWithString:@"输入你的内容" attributes:attributes];
2.如果是想在输入内容的时候就按照设置的行间距进行动态改变,那就需要将上面代码放到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];
}
一、设置textView的placeholder
UITextView上如何加上类似于UITextField的placeholder呢,其实在UITextView上加上一个UILabel或者UITextView,如果用UILable的话,会出现一个问题就是当placeholder的文字过长导致换行的时候就会出现问题,而用UITextView则可以有效避免此问题。
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{ if (![text isEqualToString:@""])
{
_placeholderLabel.hidden = YES;
}
if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
{
_placeholderLabel.hidden = NO;
}
return YES;
}
说明如下:
(1) _placeholderLabel 是加在UITextView后面的UITextView,_placeholderLabel要保证和真正的输入框的设置一样,字体设置成浅灰色,然后[_placeholderLabel setEditable:NO];真正的输入框要设置背景色透明,保证能看到底部的_placeholderLabel。
(2) [text isEqualToString:@""] 表示输入的是退格键
(3) range.location == 0 && range.length == 1 表示输入的是第一个字符
- 设置TextView的行间距
- 设置textView的行间距
- 设置textView的行间距
- TextView行间距设置
- TextView设置行间距
- textView设置行间距
- Android中设置TextView的行间距
- TextView中设置行间距的方法
- TextView中设置行间距的方法
- 设置textview lable的行间距
- iOS设置textView的行间距
- textview设置文本每行的行间距
- 一、设置textView的行间距
- 设置android textview行间距
- textView 设置行间距 行宽
- android textview 行间距设置
- android设置TextView行间距
- Android系统中设置TextView的行间距(非行高)
- C#实现 word、pdf、ppt 转为图片
- xamarin ios read txt file
- Windows Java环境搭建
- iOS基础学习篇章前言
- Android Fragment 真正的完全解析(上) add remove replace detach attach hide show
- 设置textView的行间距
- anquan123
- http://www.cocoachina.com/ios/20150907/13336.html
- android fragment
- 压缩与解压iOS
- qt QToolBox tab 文字居中
- ajax亦步刷新时,会导致某些javascript的失效解决方法
- poj 3281 最大流
- ubuntu切换到root用户