当前位置: 代码迷 >> 综合 >> 带提示(hint)的多行文本输入--UITextView
  详细解决方案

带提示(hint)的多行文本输入--UITextView

热度:68   发布时间:2024-01-11 11:09:42.0
 
  
- ( void ) viewDidLoad {
//...
comments . text = @"请输入:" ;
comments . textColor = [ UIColor lightGrayColor ];
isEmpty = YES ;
//...
}

- ( BOOL ) textViewShouldBeginEditing: ( UITextView * ) textView {
if ( isEmpty ) {
comments . text = @"" ;
comments . textColor = [ UIColor blackColor ];
isEmpty = NO ;
}
return YES ;
}

- ( void ) textViewDidEndEditing: ( UITextView * ) textView {
if ( comments . text . length == 0 ){
comments . textColor = [ UIColor lightGrayColor ];
comments . text = @"请输入:" ;
isEmpty = YES ;
}
}
注意:需要在.h文件种添加协议< UITextViewDelegate>,在.m文件种设置协议 comments.delegate=self;

  相关解决方案