一種簡單的方式實現(xiàn)帶placeholder的textview陡鹃,網(wǎng)上很多方法可以實現(xiàn),這是在stackoverflow上面看到的一位回答者寫的吮旅,感覺跟簡潔溪烤,寫下來記錄一下味咳。
下面貼出關(guān)鍵代碼:
textView初始化:
self.textView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
self.textView.layer.borderWidth = .5f;
self.textView.text = @"請?zhí)顚懜M(jìn)計劃...";
self.textView.textColor = [UIColor lightGrayColor];
代理方法:
- (void)textViewDidBeginEditing:(UITextView *)textView{
if ([textView.text isEqualToString:@"請?zhí)顚懜M(jìn)計劃..."]) {
textView.text = @"";
textView.textColor = [UIColor blackColor];
}
[textView becomeFirstResponder];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
if ([textView.text isEqualToString:@""]) {
textView.text = @"請?zhí)顚懜M(jìn)計劃...";
textView.textColor = [UIColor lightGrayColor];
}
[textView resignFirstResponder];
}