- (void)createSubView:(CGRect)frame
{
self.backgroundColor = kGrayLightColor;
_textView = [CommonMethod createTextView:_textView whoViewAdd:self frame:CGRectMake(15, 5, frame.size.width-30, /*frame.size.height-110-30-20*/35) placehold:@""];
self.placeHolderTextViewLabel = [[UILabel alloc] initWithFrame:CGRectMake(7, 6, 400/2, 20)];
[self addPlaceholdWithTextView:_textView placehold:self.placeHolderTextViewLabel text:@"以上均无,请手动输入"];
}
#pragma mark - 添加占位符方法
- (void)addPlaceholdWithTextView:(UITextView *)textView placehold:(UILabel *)placehold text:(NSString *)text
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged1:) name:UITextViewTextDidChangeNotification object:nil];
placehold.lineBreakMode = NSLineBreakByWordWrapping;
placehold.font = [UIFont systemFontOfSize:14.0f];
placehold.textColor = [UIColor grayColor];
placehold.backgroundColor = [UIColor clearColor];
placehold.alpha = 0;
placehold.tag = 999;
placehold.text = text;
[textView addSubview:placehold];
if ([[self.textView text] length] == 0) {
[placehold setAlpha:1];
}
}
#pragma mark - 添加占位通知方法 输入框要编辑的时候
- (void)textChanged1:(NSNotification *)notification
{
//NSLog(@"notification == %@", notification);
if ([[self.textView text] length] == 0) {
[self.placeHolderTextViewLabel setAlpha:1];
}
else {
[self.placeHolderTextViewLabel setAlpha:0];
}
}