UITextView基本属性
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100, 100, 200, 300)];
[self.view addSubview:textView];
self.automaticallyAdjustsScrollViewInsets = NO;
textView.font = [UIFont systemFontOfSize:13];
textView.textColor = [UIColor redColor];
textView.scrollEnabled = YES;
textView.editable = YES;
textView.delegate = self;
textView.backgroundColor = [UIColor whiteColor];
textView.text = @"https://www.baidu.com";
textView.textAlignment = NSTextAlignmentLeft;
NSLog(@"%@",NSStringFromRange(textView.selectedRange));
[textView scrollRangeToVisible:NSMakeRange(0, 1)];
textView.dataDetectorTypes = UIDataDetectorTypeAll;
UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"编辑开始前被调用,返回NO,编辑将不会开始");
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
NSLog(@"编辑结束前被调用,返回NO,编辑将不会开始");
return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"改变文本前被调用");
NSLog(@"%@",NSStringFromRange(range));
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
NSLog(@"编辑开始后被调用");
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"编辑结束后被调用");
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(@"文本变更时被调用");
}
- (void)textViewDidChangeSelection:(UITextView *)textView
{
NSLog(@"游标移动,选择范围发生变化时被调用");
}