UITextFiled不能多行,UITextView没有placeholder属性,我们就给它添加一个,遵守UITextView的代理方法<UITextViewDelegate>
1. UITextView.text = @"placeholder";
2.
- (void)textViewDidBeginEditing:(UITextView*)textView {
if([textView.textisEqualToString:@"placeholder"]) {
textView.text=@"";
textView.textColor= [UIColorblackColor];
}
}
3.
- (void)textViewDidEndEditing:(UITextView*)textView {
if(textView.text.length<1) {
textView.text=@"placeholder";
textView.textColor= [UIColorlightGrayColor];
}
}
网友评论