- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(0, 0, 375, 667);
[button setTitle:@"按键" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
//多行文本编辑框
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(20, 40, 200, 200)];
textView.text = @"hello world";
textView.font = [UIFont systemFontOfSize:16];
//layer是表现层, 控制边框的角的弧度
textView.layer.cornerRadius = 8;
//设置边框
//边框
textView.layer.borderWidth = 1;
textView.scrollEnabled = NO;
textView.tag = 10;
textView.delegate = self;
//控制编辑的 (no 就不能编辑了)
textView.editable = NO;
[self.view addSubview:textView];
//内存管理
[textView release];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"准备开始编辑");
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
NSLog(@"准备结束编辑");
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
NSLog(@"已经开始编辑了");
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"已经结束编辑了");
}
- (void)textViewDidChangeSelection:(UITextView *)textView
{
NSLog(@"已经编辑了");
}
//结束所有的编辑
- (void)buttonClicked:(UIButton *)button
{
[self.view endEditing:YES];
[[self.view viewWithTag:10] resignFirstResponder];
}