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

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值