- iOS 教程
- iOS 简介
- iOS环境搭建
- Objective-C 简介
- 创建第一款iPhone应用程序
- iOS操作(action)和输出口(Outlet)
- iOS - 委托(Delegates)
- 什么是UI元素?
- IOS加速度传感器(accelerometer)
- IOS通用应用程序
- IOS相机管理
- IOS定位操作
- IOS SQLite数据库
- IOS发送电子邮件
- IOS音频和视频(Audio & Video)
- IOS文件处理
- IOS地图开发
- IOS应用内购买
- IOS iAD整合
- IOS GameKit
- IOS 故事板(Storyboards)
- IOS自动布局
- IOS-Twitter和Facebook
- IOS内存管理
- IOS应用程序调试
IOS文本视图的使用
IOS文本视图的使用
文本视图用于显示多行滚动的文本。
重要属性
- dataDetectorTypes
- delegate
- editable
- inputAccessoryView
- inputView
- text
- textAlignment
- textColor
重要的委托方法
-(void)textViewDidBeginEditing:(UITextView *)textView
-(void)textViewDidEndEditing:(UITextView *)textView
-(void)textViewDidChange:(UITextView *)textView
-(BOOL)textViewShouldEndEditing:(UITextView *)textView
添加自定义方法 addTextView
-(void)addTextView{ myTextView = [[UITextView alloc]initWithFrame: CGRectMake(10, 50, 300, 200)]; [myTextView setText:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aiqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."]; myTextView.delegate = self; [self.view addSubview:myTextView]; }
在 ViewController.m 中执行 textView 委托
#pragma mark - Text View delegates -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange: (NSRange)range replacementText:(NSString *)text{ if ([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; } return YES; } -(void)textViewDidBeginEditing:(UITextView *)textView{ NSLog(@"Did begin editing"); } -(void)textViewDidChange:(UITextView *)textView{ NSLog(@"Did Change"); } -(void)textViewDidEndEditing:(UITextView *)textView{ NSLog(@"Did End editing"); } -(BOOL)textViewShouldEndEditing:(UITextView *)textView{ [textView resignFirstResponder]; return YES; }
修改 ViewController.m 中的 viewDidLoad方法,如下所示
(void)viewDidLoad { [super viewDidLoad]; [self addTextView]; }
结果输出
现在当我们运行该应用程序我们会看到下面的输出
上一篇:表格视图的使用
下一篇:IOS视图切换的使用
关注微信小程序
扫描二维码
程序员编程王