@property (nonatomic ,retain) UITextView * contentText;
@property (nonatomic ,retain) NSString * placeholderText;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[email protected]"这一刻的想法...";
_contentText = [[UITextView alloc] initWithFrame:CGRectMake(10, 5,260, 120)];
_contentText.backgroundColor = [UIColor clearColor];
_contentText.text = _placeholderText;
_contentText.textColor=[UIColor grayColor];
_contentText.font = [UIFont systemFontOfSize:16];
_contentText.returnKeyType = UIReturnKeyDone;
_contentText.delegate = self;
[self.view addSubview:_contentText];
}
//加占位符
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
if ([textView.text isEqualToString:_placeholderText]) {
[email protected]"";
}
textView.textColor=[UIColor blackColor];
return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView{
if ([textView.text isEqualToString:@""]) {
textView.text=_placeholderText;
textView.textColor=[UIColor grayColor];
}
}
//点击回车放弃键盘
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}