文章标题
2015-12-29 16:43
295 查看
UITextView详解
今天重新看了一下UITextView,发现很多系统方法不懂,于是便有了下面的内容
创建
今天重新看了一下UITextView,发现很多系统方法不懂,于是便有了下面的内容
创建
UITextView * textView = [[UITextView alloc] initWithFrame:[UIScreen mainScreen].bounds]; /* 1、设置文本属性:text; 2、设置文字对齐方式属性:textAlignment; 3、设置文字颜色属性:textColor; 4、设置文字字体属性:font; 5、设置编辑使能属性:editable; 6、设置背景颜色属性:backgroundColor; 7、圆角边框:layer.cornerRadius、layer.borderWidth。 */ textView.backgroundColor = [UIColor blueColor]; textView.text = @"aaasddddddddddd"; textView.font = [UIFont systemFontOfSize:50]; textView.textAlignment = NSTextAlignmentCenter; textView.editable = YES; textView.selectable = YES;//里面的内容是否可以交互,例如网址 /* UIDataDetectorTypePhoneNumber // 手机 UIDataDetectorTypeLink // URL UIDataDetectorTypeAddress // 街道地址 UIDataDetectorTypeCalendarEvent // 事件 UIDataDetectorTypeNone = 0, UIDataDetectorTypeAll */ textView.dataDetectorTypes = UIDataDetectorTypeAll; textView.allowsEditingTextAttributes = YES;//允许编辑文本属性 textView.typingAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:50]}; /* UIKeyboardTypeDefault, UIKeyboardTypeASCIICapable, ASCII UIKeyboardTypeNumbersAndPunctuation, //数字和符号 UIKeyboardTypeURL, // URL UIKeyboardTypeNumberPad, // 纯数字 UIKeyboardTypePhonePad, //(1-9, *, 0, #, with letters under the numbers). UIKeyboardTypeNamePhonePad, // 数字跟字母 UIKeyboardTypeEmailAddress, // email UIKeyboardTypeDecimalPad // 数字跟. UIKeyboardTypeTwitter // A type optimized for twitter text entry (easy access to @ #) UIKeyboardTypeWebSearch // A default keyboard type with URL-oriented addition (shows space . prominently). UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated */ textView.keyboardType = UIKeyboardTypeWebSearch; /* UIReturnKeyDefault, UIReturnKeyGo, UIReturnKeyGoogle, UIReturnKeyJoin, UIReturnKeyNext, UIReturnKeyRoute, UIReturnKeySearch, UIReturnKeySend, UIReturnKeyYahoo, UIReturnKeyDone, UIReturnKeyEmergencyCall, UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0), */ textView.returnKeyType = UIReturnKeyGo; textView.layer.cornerRadius = 10;//圆角 textView.layer.borderWidth = 3;//边框 // 7、圆角边框:layer.cornerRadius、layer.borderWidth。 [self.view addSubview:textView];
这里基本所有的系统方法都有了,欢迎补充
这里是代理方法/* 1、将要开始编辑:textViewShouldBeginEditing; 2、将要完成编辑:textViewShouldEndEditing; 3、开始编辑:textViewDidBeginEditing; 4、完成编辑:textViewDidEndEditing; 3、将要改变内容:shouldChangeTextInRange; 4、内容完成改变:textViewDidChange; 5、内容被选中:textViewDidChangeSelection。 */ - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{ return YES; } - (BOOL)textViewShouldEndEditing:(UITextView *)textView{ return YES; } - (void)textViewDidBeginEditing:(UITextView *)textView{ // 3、开始编辑:textViewDidBeginEditing; } - (void)textViewDidEndEditing:(UITextView *)textView{ // 4、完成编辑:textViewDidEndEditing; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ // 3、将要改变内容:shouldChangeTextInRange; return YES; } - (void)textViewDidChange:(UITextView *)textView{ // 4、内容完成改变:textViewDidChange; } - (void)textViewDidChangeSelection:(UITextView *)textView{ //5、内容被选中:textViewDidChangeSelection。 } - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0){ return YES;//url } - (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0){ return YES;//文本副本 }
相关文章推荐
- TableView性能优化——动态cell适应工具(UITableView+FDTemplateLayoutCell)
- Cannot load library: soinfo_link_image(linker.cpp:1635)
- Spring项目中使用Junit单元测试并配置数据源的问题
- 无意间把你的个人资料当圣诞礼物,送给了网络犯罪份子吗?
- ios 收起键盘
- Java反射
- IOS:UIPickerView设置三组数据联动的选择框(地区,上课时间段等类型数据的选择)
- 学习资料下载地址
- iOS: 关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系
- JS正则表达式
- linux下杀死进程(kill)的N种方法 【转】
- UITextField和UITextView隐藏键盘
- java图片添加水印实例代码分享
- Android 录音声波图
- 反射
- C#Timer 控件
- JavaScript 时间戳操作:
- 设计模式之简单工厂模式
- Mac下使用github
- POJ 1980 Unit Fraction Partition(dfs)