UITextView学习笔记
2016-01-04 22:39
267 查看
===================================
UITextView
===================================
1.UITextView常用属性
- (void)viewDidLoad {
[super viewDidLoad];
//天生就会滚动,就是UIScrollView的子类
//ViewController试图控制器一旦检测到自己是在NavigationController中,就会把可以滚动的视图留出一个导航栏高度的位置,因为会滚动的视图通常被设计为全屏使用。反之如果没被装在NavigationController中系统不会给你留白。
//解决方案:
self.automaticallyAdjustsScrollViewInsets = NO;
UITextView * tv = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];
tv.backgroundColor = [UIColor orangeColor];
//设置字体
tv.font = [UIFont systemFontOfSize:30];
//设置字体颜色
tv.textColor = [UIColor blueColor];
//设置文字对齐方式
tv.textAlignment = NSTextAlignmentLeft;
//设置是否滚动
tv.scrollEnabled = YES;
//设置键盘色彩
tv.keyboardAppearance = UIKeyboardAppearanceAlert;
//设置键盘样式
tv.keyboardType = UIKeyboardTypeDefault;
//设置return按键的样式
tv.returnKeyType = UIReturnKeyDone;
//设置是否自动大小写
tv.autocapitalizationType = UITextAutocapitalizationTypeNone;
//设置是否自动纠错
tv.autocorrectionType = UITextAutocorrectionTypeNo;
//设置自定义键盘
UIView * keyView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 300)];
keyView.backgroundColor = [UIColor greenColor];
//tv.inputView = keyView;
//设置二级键盘
tv.inputAccessoryView = nil;
//设置禁止编辑
tv.editable = YES;
//设置文本内容
tv.text = @"真是全都忘了";
//设置不能进行交互
tv.userInteractionEnabled = YES;
//控制器没有tag,只有UIView子类有
tv.tag = 100;
//设置代理
tv.delegate = self;
[self.view addSubview:tv];
self.view.backgroundColor = [UIColor whiteColor];
}
2.UITextView常用代理方法
#pragma mark - 实现代理
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"将要开始编辑,返回YES允许编辑,NO不允许");
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView
{
NSLog(@"将要结束编辑,返回YES允许,NO不允许");
return YES;
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{ //焦点不在tv身上
NSLog(@"已经开始编辑");
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"已经结束编辑");
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"当文本内容将要发生改变,参考UITextField");
return YES;
}
-(void)textViewDidChange:(UITextView *)textView
{
NSLog(@"当文本内容已经改变");
}
-(void)textViewDidChangeSelection:(UITextView *)textView
{
NSLog(@"选中的内容发生改变");
//获取选中文本的范围
NSRange range = textView.selectedRange;
//把选中文本得到
NSString * str = [textView.text substringWithRange:range];
NSLog(@"您选中了%@",str);
}
UITextView
===================================
1.UITextView常用属性
- (void)viewDidLoad {
[super viewDidLoad];
//天生就会滚动,就是UIScrollView的子类
//ViewController试图控制器一旦检测到自己是在NavigationController中,就会把可以滚动的视图留出一个导航栏高度的位置,因为会滚动的视图通常被设计为全屏使用。反之如果没被装在NavigationController中系统不会给你留白。
//解决方案:
self.automaticallyAdjustsScrollViewInsets = NO;
UITextView * tv = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];
tv.backgroundColor = [UIColor orangeColor];
//设置字体
tv.font = [UIFont systemFontOfSize:30];
//设置字体颜色
tv.textColor = [UIColor blueColor];
//设置文字对齐方式
tv.textAlignment = NSTextAlignmentLeft;
//设置是否滚动
tv.scrollEnabled = YES;
//设置键盘色彩
tv.keyboardAppearance = UIKeyboardAppearanceAlert;
//设置键盘样式
tv.keyboardType = UIKeyboardTypeDefault;
//设置return按键的样式
tv.returnKeyType = UIReturnKeyDone;
//设置是否自动大小写
tv.autocapitalizationType = UITextAutocapitalizationTypeNone;
//设置是否自动纠错
tv.autocorrectionType = UITextAutocorrectionTypeNo;
//设置自定义键盘
UIView * keyView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 300)];
keyView.backgroundColor = [UIColor greenColor];
//tv.inputView = keyView;
//设置二级键盘
tv.inputAccessoryView = nil;
//设置禁止编辑
tv.editable = YES;
//设置文本内容
tv.text = @"真是全都忘了";
//设置不能进行交互
tv.userInteractionEnabled = YES;
//控制器没有tag,只有UIView子类有
tv.tag = 100;
//设置代理
tv.delegate = self;
[self.view addSubview:tv];
self.view.backgroundColor = [UIColor whiteColor];
}
2.UITextView常用代理方法
#pragma mark - 实现代理
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"将要开始编辑,返回YES允许编辑,NO不允许");
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView
{
NSLog(@"将要结束编辑,返回YES允许,NO不允许");
return YES;
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{ //焦点不在tv身上
NSLog(@"已经开始编辑");
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"已经结束编辑");
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"当文本内容将要发生改变,参考UITextField");
return YES;
}
-(void)textViewDidChange:(UITextView *)textView
{
NSLog(@"当文本内容已经改变");
}
-(void)textViewDidChangeSelection:(UITextView *)textView
{
NSLog(@"选中的内容发生改变");
//获取选中文本的范围
NSRange range = textView.selectedRange;
//把选中文本得到
NSString * str = [textView.text substringWithRange:range];
NSLog(@"您选中了%@",str);
}
相关文章推荐
- UIScrollView学习笔记
- 滚动数组优化DP空间复杂度
- 【模块化】 RequireJS入门教程总结与推荐
- SOUI与WTL
- ssh+mysql 运行时报错not suitable driver
- 303. Range Sum Query - Immutable
- mvn compile错误之SunCertPathBuildException解决思路
- iOS UIPickerView 简单使用
- Easy-Ui中window窗口介绍
- UE4 Hello World 创建第一个UE4工程
- UE4 Hello World 创建第一个UE4工程
- UIView
- 一个sort命令统计hot query
- UILabel+UIImageView(动画)
- iOS: 在UIViewController 中添加Static UITableView
- UIViewController控制器的生命周期
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法(转)
- NGUI ScrollView实现循环优化
- 解决Xcode7真机调试出现:XcodeYour build settings specify a provisioning profile with the UUID
- IOS-UITableView 及自定义cell