标签:输入前清空、行间距设置、自定义键盘
-
常用方法
1.修改行间距,执行如下代码
// 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. font
设置textView中文字的字体
// 设置字体名字和字体大小
_textView.font = [UIFont fontWithName:@"Arial" size:18.0];
3.textAlignment:设置textView的文本的排列方法
// textView中的文本排列,默认靠左
_textView.textAlignment = NSTextAlignmentCenter;

4.editable
设置textView是否可被输入
5.attributedText
// 可以方便将文本插入到UITextView中。
_textView.attributedText = [[NSAttributedString alloc]initWithString:@"attributedText__-abc"];
6.inputView
设置从底部弹出的视图
// 弹出视图,默认为键盘
_textView.inputView = [[UIDatePicker alloc]init];

7.inputAccessoryView
设置弹出视图上方的辅助视图
// 弹出视图上方的辅助视图
_textView.inputAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

8.clearsOnInsertion
设置textView获得焦点,在用户使用虚拟键盘进行输入时,清除之前的文本
// clearsOnInsertion,默认为NO
_textView.clearsOnInsertion = YES;
网友评论