所謂placeholder就比如用戶看到一個輸入框,然后輸入框里面一般會有幾個淺灰色的文字,提示用戶這個地方是用來寫什么內(nèi)容的,當用戶開始輸入的時候,這幾個文字就自然而然地消失了。
好了,閑話不多說,正式開始:
本人通過Main.Storyboard拖textView的控件的:
首先,你要創(chuàng)建一個自定義類,Main.Storyboard的控制器遵守自定義類名
在View Didload方法遵守TextView的Delegate,然后實現(xiàn)textView的代理方法就可以了;代碼如下,
@interface AJBLeaveController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
@implementation AJBLeaveController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.\
self.textView.delegate = self;
self.textView.text = @"提示語";
}
#pragma mark - Text View Delegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
textView.text = nil;
textView.textColor = [UIColor blackColor];
return YES;
}
喜歡請點個贊!有不足之處請指教!謝謝