UITextView的基本用法

- (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];

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章