1、实例化
UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(40, 100, 240, 150)];
2、字体颜色
view.textColor = [UIColor cyanColor];
3、字体大小
view.font = [UIFont boldSystemFontOfSize:14];
4、对齐方式
view.textAlignment = NSTextAlignmentLeft;
5、键盘外观
view.keyboardAppearance = UIKeyboardAppearanceDark;
6、返回样式
view.returnKeyType = UIReturnKeyGoogle;
7、键盘样式
view.keyboardType = UIKeyboardTypeDefault;
8、自动纠错
view.autocorrectionType = UITextAutocorrectionTypeNo;
9、大小写类型
view.autocapitalizationType = UITextAutocapitalizationTypeWords;
10、密文,隐藏键盘
view.secureTextEntry = YES;
11、默认文字
view.text = @”http://10.0.8.8 “;
12、是否可以滑动
view.scrollEnabled = NO;
13、隐藏滑块
view.showsVerticalScrollIndicator = NO;
14、输入框是否可以编辑
view.editable = NO;
15、链接文字类型,需要和editable同时使用才有效
view.dataDetectorTypes = UIDataDetectorTypeAll;
16、实例化NSTextAttachment
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
17、设置图片
attachment.image = [UIImage imageNamed:@”1.png”];
18、设置大小
attachment.bounds = CGRectMake(0, 0, 400, 400);
19、创建富文本
NSAttributedString* str = [NSAttributedString attributedStringWithAttachment:attachment];
20、创建可变属性字符串
NSMutableAttributedString* text = [[NSMutableAttributedString alloc] initWithString:@”fssasassffsfsasffssaf”];
21、拼接文本
[text appendAttributedString:str];
22、赋值给attributedText
view.attributedText = text;
#pragma mark - 代理方法
//是否可以开始编辑
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(@”%s”,func);
return YES;
}
//是否可以结束编辑
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
NSLog(@”%s”,func);
return YES;
}
//文本宽是否可以进行超链接
-(BOOL)textView:(UITextView )textView shouldInteractWithURL:(NSURL )URL inRange:(NSRange)characterRange{
NSLog(@”%s”,func);
return YES;
}
//是否可以改变文本框
-(BOOL)textView:(UITextView )textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString )text{
NSLog(@”%s”,func);
if ([text isEqualToString:@”\n”]) {
[textView resignFirstResponder];
}
return YES;
}
//图片:只有当编辑状态为不可编辑时,才会执行此方法 点击图片时执行
-(BOOL)textView:(UITextView )textView shouldInteractWithTextAttachment:(NSTextAttachment )textAttachment inRange:(NSRange)characterRange{
NSLog(@”%s”,func);
return YES;
}
//输入框开始编辑就执行
-(void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@”%s”,func);
}
//输入框结束编辑就执行
-(void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@”%s”,func);
}
//输入框文字出现变化就执行
-(void)textViewDidChange:(UITextView *)textView{
NSLog(@”%s”,func);
if (textView.text.length != 0 ) {
filed.hidden = YES;
}else{
filed.hidden = NO;
}
}
UITextView
最新推荐文章于 2021-05-10 15:38:05 发布