UItextView设置默认文字,点击文字消失

1.<UITextViewDelegate>

2._feedback.delegate = self; UItextView实现代理

3.原理是在UITextView上加UILabel,当UItextView上有长度大于O时,UIlabel隐藏

4.代码

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"问题反馈";

    lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, 200, 20)];

    lbl.enabled = NO;

    lbl.text = @"请输入您要反馈的问题...";

    lbl.font =  [UIFont systemFontOfSize:15];

    lbl.textColor = [UIColor lightGrayColor];

    [_feedback addSubview:lbl];

    _feedback.delegate = self;

}

#pragma mark - UITextView的代理方法

- (void)textViewDidChange:(UITextView *)textView

{

    if ([textView.text length] == 0) {

        [lbl setHidden:NO];

    }else{

        [lbl setHidden:YES];

   }

}


你可能感兴趣的:(iOS)